Finding prime numbers | Sololearn: Learn to code for FREE!


Finding prime numbers

Can anyone help me with the error am making in this code?

4/14/2019 7:25:26 PM


13 Answers

New Answer


Anna, I wanted a code that would check if a number is prime, not one that loops and prints prime numbers in a range. Anyways, with your help, Anna, I have finally found how, so the new code now.


Thanks so much guys. Luis, such a nice help.


But, still not working


Luis Sepúlveda That would not check if a number is prime or not.


Thanks, Luis. Thanks everyone


Xpan How is it not working?


Nice. Looks a bit like the code that I gave you


Yes, thanks a lot


Anna, I still need your help with something


I'm not going to lie, this is an awkward way to check for prime numbers. The prime generator function doesn't do what its name says. And it shouldn't be necessary to pass "prime" as a parameter to "findPrime". But it seems to work def prime(num): i=2 while i<num: yield i i+=1 def findPrime(func,num): p = func(num) for d in p: if num%d==0: return "Is not prime" return "prime" print(findPrime(prime,5))


Denise Roßberg Oh, I don't know why I looked at the code and my thoughts completely changed.. Oopsie!

+1 I made this code a few weeks back, but I don't know if it is functional in its entirety. (I tried to fix it a bit a minute ago) Hope it helps! (Theres a bit of explanation on it)


All you gotta do is change num%i > 0 to num%2 == 0 Mod 2 only returns 2 numbers: 0 or 1 0 for even numbers and 1 for odd numbers. I wish you success! EDIT: Woops, this is not an even/odd check