I’m learning Python from an online tutorial. My problem is that when I run the script, no matter what I input the response I get is the if go == “kitchen”…
def go_to():
go = raw_input("Go to? ")
if go == Kitchen or breakfast:
print "You rumble down stairs and into the kitchen. Your mom has left some microwaved waffles on the table for you. Your big boy step sits by the counter."
elif go == "back to bed" or "back to sleep" or bed or sleep:
print "You hit snooze and roll over."
elif go == "bathroom" or "toilet" or "potty" or "pee" or "poop" or "take a sh*t" or "take a dump" or "drop a load":
print "You make a stop at the head first."
go_to()
else:
print "That is not a command I understand."
go_to()
go_to()
As Ignacio says, you need a new tutorial.
The expression
go == Kitchen or breakfastwill be true if either of the subexpressionsgo == Kitchenorbreakfastevaluate toTrue. This will happen ifgoevaluates to the same object asKitchen, or their type defines an__eq__method which defines equality for them, or it will be the case ifbreakfastis an object that is notNone.The way to check if a variable contains a value in a list is:
Note also that your code doesn’t show where the variables
Kitchenandbreakfastare defined, and your indentation is incorrect.