Big If not returning


#1

My code:

def the_flying_circus():
    if (3 == 4-2 or False):    # Start coding here!
        print True
    elif (3 != 4-3):
        print True
    else:
        print True
print the_flying_circus()

is producing error:

Oops, try again.
the_flying_circus() returned the value None, did you forget to add a return statement?

I've tried return, print, just function name; with an argument and without, can't get the darmed thing to work. What am I looking right at but not seeing? Thx.
`


#2

Try to remove the last print in front of the the_flying_circus on the last line and see what is happening


#3

Edit: trying to make this clear for other newbs like me.
If I remove the last print line, I get the same error, which is what prompted me to add it in the first place.

If I remove only the word "print" in that line, so the last line is

the_flying_circus()

I get this error:

Oops, try again.
the_flying_circus() returned the value None, did you forget to add a return statement?

#4

@jako42 The error message is pretty self explanatory: You forgot to add a return statement. Every function has to have something to return, or give back to the user. In the instructions, it tells us to make sure the function returns True, so you must add a return statement, like this:

def the_flying_circus():
    if (3 == 4-2 or False):    # Start coding here!
        print True
    elif (3 != 4-3):
        print True
    else:
        print True
    return True
print the_flying_circus()

That should do it for you. :slight_smile:


#5

Thanks @chipjumper36731. I did try a return command but must have had it indented in the wrong place since where it is doesn't make sense to me. Wait, did we learn the return command yet? I guessed it based on the error message.

Here's the logic I don't understand. WIthin the function:

  1. If statement returns true (could be "A" or anything)
  2. Elif statement returns true (could be "B")
  3. Else statement returns true (could be "C")
  4. Independently, the function requires a Return True (the answer this problem is looking for). It's not based on a conditional above since the indents are equal to If sections. Trick question?

#6

If I understand the code right, you should replace the print everywhere with return and the function should work as intended.

The default return value for any function in Python that does not have a return statement is None.


#7

Show me your code now.


#8

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