Problem with "Big if"


#1

Could someone check this code for me please? It’s not returning/printing what expected.
Thanks!

def the_flying_circus(answer):
    if answer == 5: 
      	return True
      	print "Your answer is true"
      
    elif answer == 6:
        return False
      	print "number six not accepted"
      
    else:
     	  return False
print "This is not True"	
      	    
print the_flying_circus(5)

#2

if you then include what you are expecting and whats different, we can better explain it


#3

The answer being (5) it should print “Your answer is true” but it’s actually printing " This is not True"


#4

"This is not True" is always printed, given its outside the function

by default, a function returns None at the end, if we want to return something else at the end of the function, we can use the return keyword, thus when return keyword is reached the function ends.


#5

I’ve changed the code a bit:

def the_flying_circus(answer):
    if answer == 5: 
      	return True
      	print "Your answer is true"
      
    elif answer == 6:
        return False
      	print "number six not accepted"
      
    else:
     	  return False
      	  print "This is not true"
      	  
print the_flying_circus(6)

Now the answer being (6) it should print “number six not accepted” but it’s not. I’m also getting indentation errors.


#6

if you get indention errors, re-indent around those lines

i explained why this is the case? read my previous answer


#8

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