I am trying to make my own code, which I believe is important to the learning process, rather than come to the QnA whenever I get stuck. Alas, I needed to get some help on this one.
No matter the number I put in, it prints False unless I input 0 which then returns True. I was hoping someone could explain why this is exactly.
def is_prime(x): for n in range(0,x): if n%2==0: return False elif x == 0: return False elif x <= 1: return False break else: return True print is_prime(3)
This is a similar code that I found that works:
def is_prime(x): if x < 2: return False for n in range (2,x): if (x % n) == 0: return False return True
I just wanted to know what the exact difference is.