I'm not sure how to use if statements


#1

I need a bit of help

It doesn't show any error messages and shows the task as being completed

I expect it to print out the strings depending on the user input but it just returns none

question = raw_input("Do you like programming in python?")

question.lower()

def the_flying_circus():
    if question == "yes" or "yeah":  
        print "anything"
        return True
    elif question == "no":
        print "nothing"
        return False
    else:
        print "please answer the question"
        return False

#2

You need to call your function after defining it for the code inside your function to run,

def the_flying_circus():
    if question == "yes" or "yeah":  
        print "anything"
        return True
    elif question == "no":
        print "nothing"
        return False
    else:
        print "please answer the question"
        return False

print(the_flying_circus())

#3

It runs now but it only returns the first statement


#4

Yes because if/else statements are conditions and if that condition is met then your code will return the value assigned to that condition. Your code cannot return all values at once otherwise what would be tho point of having conditional operators? :slight_smile:


#5

when I run the code and input "no" it returns "anything" and True


#6

That's only because of this line,

if question == "yes" or "yeah":

you must type question == for both outcomes,

if question == "yes" or question == "yeah":


#7

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