好吧,所以答案可能很明显,但我不知道正确的方式让程序根据用户输入的内容做出不同的响应。语法问题 - if/else和raw_input()
octopusList = {"first": ["red", "white"],
"second": ["green", "blue", "red"],
"third": ["green", "blue", "red"]}
squidList = ["first", "second", "third"]
squid = random.choice(squidList)
octopus = random.choice(octopusList[squid])
名单和鱿鱼和章鱼随机生成一个短语
resp = raw_input("Please Type Something")
while resp !=1:
if resp == octopusList:
print squid + " " +octopus
break
elif resp == "Something":
print "Elephants are pachyderms"
break
else:
print "That's another text to think about."
break
print "One More Comment"
据说这是如果用户输入的任何octopusList打印鱿鱼+“” +章鱼。或者,如果用户输入“Something”,则应该返回“Elephants is pachyderms”这个短语。如果用户输入任何东西,它应该返回“这是另一个需要思考的文本”。最后,它应该打印“更多评论”。实际上,无论用户输入什么内容,它都会跳转到其他地方。
它通向Else,所以我没有得到关于if和elif的东西......感谢你能照亮的任何光。
请编辑您的问题,并格式化您的所有代码。很难弄清楚它应该做什么,特别是因为它是Python。 – GreenMatt 2010-07-16 19:23:25
即使缩进后,我仍然不太确定该程序应该做什么... – 2010-07-16 19:24:32