The Big If? What If?


#1



Hello,

I'm Henry, a future computer programmer/network administrator in training and looking to get insight on how python can increase my workflow productivity.


I've completed the task, but the out put wasn't what I expected to come out. Could you please explain why my output didn't render any of the strings I set in it?


I expected my code to output the strings in if the statement if it held true.


def the_flying_circus():
    if True > False and not True < False:
        return True
        print "The monkey is flying"
    elif False == False or True == True:
        return True
    else:
        return True
        print the_flying_circus()


#2

Hi @microslayer56867,

Place this print statement before the return statement ...

print "The monkey is flying"

When a return statement executes, function execution terminates. Therefore, the print statement that you have placed right after the return statement cannot execute in its current position.

Remove the indentation from this statement, so that it is outside the function ...

print the_flying_circus()

The it will be able to call the function, causing it to execute.


#3

Hello @appylpye,

Thanks for reviewing my code and telling me the issue. I will run it again
when I get to school with the specified modifications.

V/r

Henry


#4

Let us know how it works out.


#5

Hi programmers, I am a beginner and having same problem as microslayer. Below is my code:

Make sure that the_flying_circus() returns True

def the_flying_circus():
if 3 > 5 and True:
print "monica".
return True
elif 3 < 5 or True:
print "i love you".
return False
else 0 # You'll want to add the else statement, too!

I keep getting this error message :
File "python", line 3
if 3 > 5 and True:
^
IndentationError: expected an indented block
Please help any suggestion is welcome thanks.


#6

Hello ojemba! Hope you're doing well

Your code isn't far from being correct and can be simplified even further. I have the first statement in the first two "if" statements changed to look like this:

  1. if 3 < 5 and True : (this will yield True and True, which is True)

  2. if 3 > 5 or True : (this will yield False or True, which is Fault)

Your code should look like this:

def the_flying_circus():
if 3 < 5 and True:

    return True
elif 3 > 5 or True:

    return False
else :
    return True

print the_flying_circus()


#7

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