Is_prime even stuck-er


#1



Ok so last post wasn't really a hit - I can see why, a painful to watch newbie who has no clue of the logic and the higher level thinking required isn't the most tempting post to reply to.

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

I explicitly mark x == 2 and the door code contradicts my code.
The error says: Oops, try again. Your function fails on is_prime(2). It returns False when it should return True.


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


#2

2 is less than 3 so gets returned as False.

1 is a common divisor of all integers, so not a good test for Primeness.


#5

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