dimanche 19 mars 2017

Python if/else defers to wrong branch

I'm writing an Interactive Fiction game for a school project, and for some reason, when I try to use an if/else statement with input (or raw_input), the if else statement defers to the wrong branch regardless of what I input. Here is the code in question:

`print("""You enter the room to the south. Upon entering you mark that it is pitch black, and if you were in the famous text adventure Zork, you would be likely to be eaten by a grue. Thank the programmer for small favors. Unlike in that game, you have a candle, a single stick of 100-year-old dynamite, and that matchbook from earlier. You just knew that would be useful! The candle and the dynamite have the same shape, size, and weight.""") choice1 = True while choice1 == True: choice2 = input("Will you strike a match? ") if choice2 == "Yes" or "yes" or "y": print("""It flickers for a second. You can kind of make out which is which, but alas! They are both covered in red paper! You are beginning to sweat from the nervousness.""") choice1 = False elif choice2 == "No" or "no" or "n": print("""Okay. I can wait, you aren’t leaving this room until you light a match. You will eventually light a match, but I can wait until you do.""") choice1 = True else: choice1 = True

The if/else statement is treating anything that I type as though I typed yes. Can anyone help me with this error?

Aucun commentaire:

Enregistrer un commentaire