6. is_prime


#1

Hey guys I have the solution for this problem but I thought a recursion could solve this problem as well. This is what I thought. If I am totally on the wrong track please tell me. Otherwise, I would be curious if it could work out this way as well
def is__prime(c):
if c==2:
return True
elif c<2:
return False
elif c>2:
c%is__prime(c-1)==0
return False
else:
return True
print is__prime(15)


#2

Your function returns a boolean, do you really want do do c mod <bool> ?

You can implement loops with recursion, but there's nothing to gain in that (especially since python has a preference for being imperative)


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.