The Big If


#1

https://www.codecademy.com/en/courses/python-beginner-BxUFN/4/1?curriculum_id=4f89dab3d78889000300009626

What its wrong with my code ??

the_flying_circus = True
def the_flying_circus():
if answer == 2 or answer >= 4: # Start coding here!
print "You are right!"
# the code inside this block!
elif answer != 2 and answer ==1 :
print "You are wrong!"
else:
print "Nothing"

the console says
''Oops, try again. The following exception was raised when calling the_flying_circus(): NameError: global name 'answer' is not defined''

I dont understand if i need to define the_flying_circus = True, and if my conditionals i should write if answer or not


#2

You hit just hit the nail on the head. You don't need to use answer in your if statements, nor do you need the initial call of setting the_flying_circus equal to true. (That's what our function is supposed to do).


#3

okk thank you! and i dont understand other things to .For example in the if i need to write a expression that is true like ( 2 == 2) and in th elif i need to write a expression false like ( 2 != 2)


#4

That is correct, the if statement should evaluate to true and the elif statement should evaluate to false.


#5

and the else should evaluate what ?


#6

Allow me to backtrack for a moment.

The if statement should both evaluate to and return true.

The elif statement should also both evaluate to and return true (One might even call it not false :wink:).

The else statement should return false. Else statements don't require expressions.


#7

yeah but im confused ,you said the elif should evaluate to false in the other message ,and in this one you said elif should evaluate to and return true


#8

Which is why I said allow me to backtrack.


#9

def the_flying_circus():
if 2 > 1 and 3 < 4
print "You are right!"
# the code inside this block!
elif 2 < 1 and 3 > 4
print "You are wrong!"
else:
print "Nothing"

when i run code this apper "Oops, try again. An exception was raised while running your code, see the console window for the error message."
but whats wrong if the if is true and the elif is false ,the elif need to be the opposite ,or any expression false?


#10

You are printing strings instead of returning boolean values.


#11

Here is a basic outline of what the code should do:

def my_function():
    if true:
        return true
    elif false:
        return false
    else:
        return false

#12

aaah thak you ! i run this one and work!!

def the_flying_circus():
if 2 > 1 and 3 < 4:
return True
# the code inside this block!
elif 2 < 1 and 3 > 4:
return False
else:
return Nothing

but two more things and i live you ,why return true instead print true ? because until this lesson we dont learn the function return,just learned the print one,thats why i write print . And the elif shoul evaluated any expression false or should be exactly the opposite of the expression if ?


#13

The fourth part of the instructions literally says:

04. Finally, the_flying_circus() must return True when evaluated.


#14

def the_flying_circus():
if 3 == 3 or 4 != 5:
print('The flying cirus is awesome')
return True
elif 3 > 2 and 4 < 6:
print ('The flying circus is on point')
return True
else:
print ('The flying circus is lame')
return False
the_flying_circus()


#15

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