+ 5
Finding prime numbers
Can anyone help me with the error am making in this code? https://code.sololearn.com/cDJC4I9ci6jK/?ref=app
13 Respostas
+ 3
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.
https://code.sololearn.com/cDJC4I9ci6jK/?ref=app
+ 6
Thanks so much guys.
Luis, such a nice help.
+ 4
But, still not working
+ 3
Luis SepĂșlveda That would not check if a number is prime or not.
+ 3
Thanks, Luis.
Thanks everyone
+ 3
Xpan How is it not working?
https://code.sololearn.com/c5mgzem0Bfxw/?ref=app
+ 3
Nice. Looks a bit like the code that I gave you
+ 3
Yes, thanks a lot
+ 3
Anna, I still need your help with something
+ 2
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))
+ 1
Denise RoĂberg Oh, I don't know why I looked at the code and my thoughts completely changed.. Oopsie!
+ 1
https://code.sololearn.com/cMlWZQb13V4G/?ref=app
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)
- 1
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