Is_prime


#1


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

Following is the error message:

Oops, try again. Your function fails on is_prime(3). It returns None when it should return True.


Replace this line with your code. 
def is_prime(x):
    if x<2:
        return False
    elif x==2:
        return True
    else:    
        while x>2:
            for n in range(2, x-1):
                if x%n==0:
                    return False
                else:
                    return True
            break


#2

def is_prime(number):
    divisor = [num for num in range(1, number+1) if number % num == 0]
    return True if len(divisor) == 2 else False

Well, I also couldn't solve it as directed by Codecademy. So try my code.


#3

you need change range Terminal
Look at this:
range(2, 8)
[2, 3, 4, 5, 6, 7]
Also, you need more False conditions. What will your function return, if n==x?


#4

Thanks! It worked. Have a great weekend!


#5

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