Not sure what I'm doing wrong?


My code works and runs the way I want, but codeacademy keeps telling me I did it wrong?

def is_prime(x):
    if x == 2:
        print True
    elif x % 2 == 0:
        print False
    elif x < 2:
        print False
        print True 


This code will accept all odd numbers as prime except 1. While all prime numbers are odd except for 2, not all odd numbers are prime.

9 is divisible by 3
15 is divisible by 5
21 is divisible by 7

and so on...


Does Codecademy accept print in the place of return? (Instructions specify return)
Also, I found the range() function to be helpful in this exercise. (My own thread is listed if you want to check it out; it starts with the number and title of the exercise.)


The two are not interchangeable. When a function returns something, the data is passed back to the caller for further action, such as printing, storing, processing, etc. If return is specified in the instructions, then use return.

 if x < 2: return False


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