I am new to programming and am learning Python with the book Learning Python the Hard Way. I am in Exercise 36, where we are asked to write our own simple game.
http://learnpythonthehardway.org/book/ex36.html
(The problem is that when I am in the corridor (more precisely, in the “options”) and I write “gates”, the game responds as if I said “man” from the “old man”, etc.
What am I doing wrong?)
EDIT: I shouldn't have written "if" old man "or" person "by choice", but instead "choice" follows after each option.
However, the following problem. A man never gets up and does not smoke me, he frowns. Why doesn't the game go to this elif?
experiences = [] def choices(): while True: choice = raw_input("What do you wish to do? ").lower() if "oldman" in choice or "man" in choice or "ask" in choice: print oldman elif "gate" in choice or "fight" in choice or "try" in choice and not "pissedoff" in experiences: print "The old man frowns. \"I said, you shall not pass through this gate until you prove yourself worthy!\"" experiences.append("pissedoff") elif "gate" in choice or "fight" in choice or "try" in choice and "pissedoff" in experiences and not "reallypissed" in experiences: print "The old man is fed up. \"I told you not to pass this gate untill you are worthy! Try me again and you will die.\"" experiences.append("reallypissed") elif "gate" in choice or "fight" in choice or "try" in choice and "reallypissed" in experiences: print "The old man stands up and curses you. You die" exit() elif "small" in choice: print "You go into the small room" firstroom() else: print "Come again?"
EDIT: FIXED IT !!
def choices(): while True: choice = raw_input("What do you wish to do? ").lower() if choice in ['oldman', 'man', 'ask']: print oldman elif choice in ['gate', 'fight', 'try'] and not 'pissedoff' in experiences: print "The old man frowns. \"I said, you shall not pass through this gate until you prove yourself worthy!\"" experiences.append("pissedoff") elif choice in ['gate', 'fight', 'try'] and not 'reallypissed' in experiences: print "The old man is fed up. \"I told you not to pass this gate untill you are worthy! Try me again and you will die.\"" experiences.append("reallypissed") elif choice in ['gate', 'fight', 'try'] and 'reallypissed' in experiences: print "The old man stands up and curses you. You die" exit() elif "small" in choice: print "You go into the small room" firstroom() else: print "Come again?"
Thank you for your help:).
source share