Is_prime


#1

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

hey my code does not run when i pass value 9
what to do ???


#2

This will return True for all odd numbers. The if statement should not have an else branch.


#3

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