我是编程的新手,正在学习Python学习Python的艰难之路.我正在练习36,我们被要求编写自己的简单游戏.
http://learnpythonthehardway.org/book/ex36.html
(问题是,当我在走廊(或者更确切地说,在"选择"中)并且我写'门'时,游戏回应就好像我说"老人"的"男人"等.
我究竟做错了什么?)
编辑:我不应该在选择中写出'if"oldman"或"man",而是在每个选项之后选择'选择'.
然而,下一个问题..男人从不站起来诅咒我,它一直皱着眉头.为什么游戏没有进入那个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?"
编辑:固定它!
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?"
感谢你的帮助 :).