gpt4 book ai didi

Python (LPTHW) 练习 36

转载 作者:太空狗 更新时间:2023-10-30 01:06:54 25 4
gpt4 key购买 nike

<分区>

我是编程新手,正在通过《艰难地学习 Python》一书学习 Python。我在练习 36,要求我们编写自己的简单游戏。

http://learnpythonthehardway.org/book/ex36.html

(问题是,当我在走廊(或更准确地说,在“选择”中)并且我写“门”时,游戏的响应就好像我说的是“老人”之类的“男人”。

我做错了什么?)

编辑:我不应该写“if "oldman"or "man"in choice”,而是在每个选项后加上“in choice”。

然而,下一个问题.. 这个人从来没有站起来咒骂我,它一直皱着眉头。为什么游戏没有进行到那个 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?"

感谢您的帮助:)。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com