以及即时通讯学习蟒蛇和即时通讯尝试使这种文本游戏和即时通讯卡 on while循环...什么即时通讯试图做的是有可用的东西,并比较用户raw_input到这个列表中,如果他们在5次尝试中选择了正确的一个,则继续,否则消失。 这里是我的代码:蟒蛇嵌套循环与中断
def die(why):
print why
exit(0)
#this is the list user's input is compared to
tools = ["paper", "gas", "lighter", "glass", "fuel"]
#empty list that users input is appended to
yrs = []
choice = None
print "You need to make fire"
while choice not in tools:
print "Enter what you would use:"
choice = raw_input("> ")
yrs.append(choice)
while yrs < 5:
print yrs
die("you tried too many times")
if choice in tools:
print "Well done, %s was what you needeed" % choice
break
但不添加选择列出yrs
,它适用于只是一个while循环 但随后去去永远存在,直到工具列表中的项目之一输入为用户输入然而 ID喜欢它限制在5次尝试,然后用输入:die("You tried too many times")
但它给我死的消息第一次尝试后直... 我正在寻找这个论坛,没有找到令人满意的答案,请大家帮我
这是无效的Python语法。修复代码的缩进。 –