Chris D
Chris D

Reputation: 13

Boolean and Conditionals

I'm currently working my way through Codecademy and have come to the final lesson in the Python "conditionals and Control Flow". It asks for the following code to return true, but when I try to submit this it outputs "none". What am I doing wrong?

def the_flying_circus():

    if 5 == 5:
        print "True"
    elif not True:
        print "False"
    else:
        print "something else"

Upvotes: 1

Views: 1576

Answers (4)

JonB
JonB

Reputation: 846

Aside from the nonsensical nature of the question the corrected version would be (assuming it's blackboxed anyway):

def the_flying_circus():
    return True

But in the spirit of meeting CodeAcademy's requirement:

def the_flying_circus():
    if 5 == 5:
        return True
    elif not 5 == 5:
        return False
    else:
        return "Dumb exercise"

Upvotes: 1

Bhargav Rao
Bhargav Rao

Reputation: 52181

Now that the answer is obvious, I would suggest to do this instead

def the_flying_circus():
   return 5 == 5

Thanks to the Python developers, == returns True and False automatically

Or as JonB mentioned in a comment, We can rather hard-code the value

def the_flying_circus():
   return True

As 5 is always equal to 5 No matter what happens on earth.

Upvotes: 1

Jonathan Davies
Jonathan Davies

Reputation: 884

You have to change the print to return and remove the quotes on the True and False.

Upvotes: 0

Nelson Teixeira
Nelson Teixeira

Reputation: 6580

Change "print" statements by "return". That should do it.

Upvotes: 0

Related Questions