def is_prime(x): if x>1: if x==2: return True else: for n in range(2,x): if x%n==0: return False break else: return True else: return False
I dont know what am i doing wrong
a function ends the moment a return keyword is reached (even when return keyword is reached in loop)
x=9 the first case tested by the loop is
if 9 % 2 == 0
which evaluate to false. so else runs, True is returned, the function ends
What is the condition for a number to be a prime number?
x shouldn’t be divislbe by any number in range, this is clearly not happening at the moment
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.