Help please


Why is this not printing "True"?

def the_flying_circus():

if answer == "Steve" or "Mark":   
    return "I did this wrong"

elif answer == "Danny":
    return "True"

    print "I did this wrong" 

print the_flying_circus("Danny")


Conditional Statements in programming languages don't work like how we speak them to a large extent (this becomes helpful when dealing with complicated comparisions but obtrusive when they're simple).
The following part of your code will be giving you an error:

if answer == "Steve" or "Mark":

It should be:

if answer == "Steve" or answer == "Mark":

That should fix it


interesting, i changed it but got another error message...

The following exception was raised when calling the_flying_circus(): NameError: global name 'answer' is not defined


That's because there is no answer parameter (forgot to look at that :stuck_out_tongue: )
change the first line of the function to:

def the_flying_circus(answer):
    # Function code

You are getting the error since you haven't passed any parameter, nor is there a variable called answer in the code. If you define ans = "Danny" BEFORE the function, and don't pass "Danny" to the function in the print statement, then it'll work too (but I guess the exercise won't accept that) (emphasis on before, since Python is an interpreted language)


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