Topic: Loops, Prime. What's wrong with my code?


#1

def is_prime(x):
for n in range(2, x):
if (x % n == 0):
print "not prime"
return True
n = n+1
else:
print "prime"
return False
is_prime(19)


#2

whats the error you are getting?
remove this line

?


#3

I made some modifications to my code and this one works now

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