6. is_prime - What´s wrong with this code?


#1

import math 
def is_prime(x):
    x >= 2
    for n in range(2, x-1):
        if x % n == 0:
            return False
        else:
            return True

What´s wrong with this code?


6 is_prime - What's wrong w/ my code?
#2

Did you mean to write this as an if statement?

The else can be removed, and the return True needs to be moved to left so it is in neither the if nor the for statement. We need the loop to complete iteration.


#4