Not sure what I'm doing wrong?


#1


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

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
    else:
        print True 
            
is_prime(0)


#2

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...


#3

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.)


#4

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

#6

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