Is_prime


#1

Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

https://www.codecademy.com/courses/learn-python/lessons/practice-makes-perfect/exercises/isprime?action=resume_content_item

def is_prime(x):
if x<2:
return False
if x == 2:
return True
for n in range(2,x):
if x%n ==0:
return False
else:
return True
print is_prime(9)

this code works for all numbers except x=9. whats wrong in this code?


#2

You could add prints in your code to write out what’s being done.

That’s a really strong statement. There exist a whole lot of numbers.


#3

9 is not prime
3 * 3 = 9


#4

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