Why does is_prime fail for some numbers?
If your code is failing for some numbers, it’s likely because you’re
returning too soon, or because you’re
returning the wrong thing in the wrong place. Without giving away the answer, take a look at the example control flow pseudo code below:
# From hint: any number less than 2 is not prime if x is less than 2: return x is not prime # This loop is where we put our number to the test and return False # so the function exits immediately if x isn’t prime for n from 2 to x: if x is evenly divisible by n: return x is not prime # If we made it here, our number must be prime because none # of the other return statements were executed! return x is prime