Is_prime


#1




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


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


#2

I am doing something wrong here cant figure out. need help.


#3

here:

if  x % n == 1:

you want to check if the remainder equals zero, if this is the case, return False.

Also, a function ends the moment a return keyword is reached.This currently happens in the first iteration of your loop, you only should return True after the loop has finished running (hint: indention)

If you need more help, post an updated version of your code


#4

Worked :slight_smile: thanks, was able to fix it.


#5

#6

well done! you did most of the work