mardi 30 mars 2021

Second if statement being treated like else [closed]

I'm very new to Python 2 and am using only the most basic of code to try and make a simple text based game. I've made a few if/else statements where you have to type in one specific thing to go further or it will say it doesn't understand and prompt you to type the action again, and those work well. Now I'm trying to present two options that you can choose from, where either action will lead to a different part of the game, but the code is only checking to see if the first if statement is correct and leading directly to the else if it isn't, even if the action typed fits the second if statement correctly. It's just being skipped over in favor of the else for some reason and I'm too much of a newbie to understand why. I've also tried to have the second statement be ifel, and that hasn't worked either.

Here's the code:

def bedroom():
   # Bedroom after intro
   print """
   You step back into the bedroom. The moon still shines brightly through your window, illuminating the
   otherwise dark space.
   
   There is a nightstand next to the bed, and there are two doors leading out of the room. One goes out to the main
   part of the house, and the other leads to the master bathroom."""
   players_guess = raw_input(action).lower()
   while True:
       if players_guess == "go to main part of house":
           main_house()
           break
       if players_guess == "go to bathroom":
           bathroom_post_mirror()
           break
       else:
           print "I'm sorry, I don't understand that."
           players_guess = raw_input(action).lower()

Aucun commentaire:

Enregistrer un commentaire