What am I doing wrong? is_prime


#1



is_prime


"Your function fails on is_prime(0). It returns None when it should return False"


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


#2

You should set this

outside, above the for loop.

Also, what do you need break to do for you?

Your second if statement and its return statement is fine, and you don't need to add a break. The else statement too is needless. All you need do is return the for loop as True at the end.

I hope this helps! :slight_smile:


#3

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