当前位置:  开发笔记 > 编程语言 > 正文

Python(LPTHW)练习36

如何解决《Python(LPTHW)练习36》经验,为你挑选了0个好方法。

我是编程的新手,正在学习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?"

感谢你的帮助 :).

推荐阅读
N个小灰流_701
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有