(solved) Is_prime


#1



Error message: Oops, try again. Your function fails on is_prime(-7). It returns True when it should return False.


I think my code is right, 7 is a prime number, so my function should return True. I don't know why the error message says that it should return False. Bug? Is there something wrong in my code?


def is_prime(x):
    x=abs(x)
    prime=True
    if x==0:
        prime=False
    elif x==1:
        prime=False
    elif x==2:
        prime=True
    else:
        for n in range(2, x-1):
            if x%n==0:
                prime=False
    return prime


#2

Read the part of the instructions that says what a prime number is, they disqualify -7


#3

You're right, thanks you!! (:


#4

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