I'm new to programming and am learning Python with the book Learning Python the Hard Way. I'm at exercise 36, where we're asked to write our own simple game.
http://learnpythonthehardway.org/book/ex36.html
(The problem is, when I'm in the hallway (or more precisely, in 'choices') and I write 'gate' the game responds as if I said "man" of "oldman" etc.
What am I doing wrong?)
EDIT: I shouldn't have written 'if "oldman" or "man" in choice' but instead put 'in choice' after every option.
However, next problem.. The man never stands up and cursus me, it keeps frowning. Why does the game not proceed to that 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?"
Thanks for all your help :).