I stayed on this exercise for about 30 mins before going to the forums. I discovered the fact that once a return statement is stated the loop ends. This forced me to use a variable to store True or False and then after return the variable. I was wondering if there was a way to do this without using a variable to store True and False. From what I know you can't, but I am new to coding, so I have no idea. Anybody know a way?
def is_prime(x): pr = False if x == 0: pr = False elif x == 2 or x == 3: pr = True elif x == 1: pr = False else: for n in range(2, x - 1): if x % n == 0: pr = False break else: pr = True return pr