Is_prime


#1

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

and if i write the else outside the loop it says local n after assignment something like that when i make if elif inside the loop it gives error on is_prime returns true

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

this another code i made
error:
Oops, try again. Your function fails on is_prime(1). It returns 1 when it should return False.


#2

Use print statements to follow along in what it does, and compare to what you think it should do.


#3

okay thanks i already passed it


#4

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