Ok I get the following error message "Oops, try again. Your function fails on is_prime(2). It returns False when it should return True." again and again, although going through my code I don't really see how could my function return "False" for x = 2.
def is_prime(x): if x < 2: return False else: for i in (2, x-1): if x % i == 0 and i != x: return False break else: vcdt = True return vcdt print is_prime(2)
I thought I had shortcutted that error including "i != x" as a condition on line 6 so when x = 2 the code should just ignore that if and get directly to the else and thus return "True". I know I could just add a line like "if x == 2 \ return True" but I'm trying to get a more generic code.
Do any of you see the problem?
Thanks a lot and cheers!
P.S.: is that break on line 8 necessary to break not just the loop but also the function, or does the function break by itself when returning something?