6. is_prime


Sorry, where is my mistake.

error messages:
Oops, try again.
Your function fails on is_prime(9). It returns True when it should return False.

def is_prime(x):
    if x > 2:
        for n in range(2, x):
            if x % n == 0:
                return False 
                return True
    elif x == 2:
        return True
        return False


Execute it in your head for x=9 and see which return statement you end up on. Then consider how you got there and what it should be doing differently.
Alternatively you can add print statements that explain what it does as it runs.


Thank you. I found the problem:relaxed:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.