I cannot find my error


#1



https://www.codecademy.com/courses/python-intermediate-en-rCQKw/0/6?curriculum_id=4f89dab3d788890003000096


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


well, -7 is prime, isnt it?


def is_prime(x):
    f=0
    if x<0:
        x*=-1
    print range(2,x/2+1)
    if x==0:
        f=1
    elif x==1:
        f=1
    else:
        for n in range(2,x/2+1):
            if x%n==0:
                f=1
    if f==0:
        return True
        print True
    else:
        return False
        print False


#2

negative numbers are never prime numbers.


#3

All right! i made the right changes and the results came up! thanks! @stetim94


#4

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