- 1

Create an algorithm that detects prime numbers using simple libraries

4th Sep 2021, 1:42 PM
Pallemoni Jyothi
Pallemoni Jyothi - avatar
8 Answers
+ 2
Show your attempt First
4th Sep 2021, 2:00 PM
Pariket Thakur
Pariket Thakur - avatar
+ 2
write a for loop in range(2,num) if num is divisible by any "i" it means num is "not prime" else "num" is prime.. apply the same math logic which you learned in the school..
4th Sep 2021, 2:36 PM
Ratnapal Shende
Ratnapal Shende - avatar
+ 2
Well library name is sympy Example: import sympy print('prime') if isprime(int(input() or 2) else print('not prime ')
4th Sep 2021, 6:37 PM
Mohd Aadil
Mohd Aadil - avatar
+ 1
Pallemoni Jyothi Python Is very very very large, thus, Is posibole, search in Google your ask
4th Sep 2021, 4:14 PM
CGO!
CGO! - avatar
0
import math def is_prime(n): if n == 2: return True if n % 2 == 0 or n <= 1: return False sqr = int(math.sqrt(n)) + 1 for divisor in range(3, sqr, 2): if n % divisor == 0: return False return True print(is_prime(12) ) print(is_prime(2) )
4th Sep 2021, 2:52 PM
Gigi
0
Gigi , you are showing a really nice code to help someone solving a task. we all appreciate this very much!  (this is my personal statement - but it is not to criticize someone !!) but there is an issue by giving a ready-made solution, when the op has not done and shown his attempt first. as a part of the community i believe that learning by doing is more helpful, than just using a shared solution. we should act more as a mentor.  it is a very successful way when we are giving hints and help, so that the op is able to solve his task by himself. it would be great if you are going to help us to keep sololearn what it is: â–Șa unique place to learn (we are a "self" learning platform!) â–Șan absolutely great community that is willing to help other people  â–Șa great resource of people which has an unbelievable knowledge in coding and a long lasting experience â–Șa place to meet people and to discuss with them all the possible points of view thanks for your understanding
4th Sep 2021, 2:54 PM
Pariket Thakur
Pariket Thakur - avatar
0
Dear HrCoder, I know what you mean but I partially disagree. I started with programming 4 years ago and I know how it feels when you really don't know how to begin. I have learned a lot from solutions at the beginning and then of course with practice. I don't know the level of the person who asked this problem, think is a beginner because I did this when I was trying to learn code, I remember that I solved it with sieve of Eratosthenes (yes, somebody explained it to me). If it is a crime, I ll stop to share solutions to people who didn't provide an attempt, although I dont agree. Otherwise I ll continue.
4th Sep 2021, 3:09 PM
Gigi
0
num=int(input()) for i in range(2,num): msk=[] for j in range(1,i+1): if i%j==0: msk.append(1) if sum(msk)==2: print(i
5th Sep 2021, 1:13 PM
M.Peymany
M.Peymany - avatar