【发布时间】:2017-12-18 19:28:45
【问题描述】:
到目前为止,这是我的代码,它有效:
print('Welcome to choose your own adenture.')
print('You enter a room with two doors. Do you want to enter the red door or the white door?')
door = input()
while True:
if door == 'white':
print("there was a dragon behind the door. It ate you and you died.")
break
elif door == 'red':
run_or_dead = input("there is a bear behind the door. Do you want to wave your arms and shout, or play dead?")
while True:
if run_or_dead == 'wave':
print("Nice try, but the bear did't buy it. It ate you and you died.")
break
elif run_or_dead == 'play dead':
print("Nice try, but the bear did't buy it. It ate you and you died.")
break
else:
run_or_dead = input('Not a valid answer. Do you want to wave or play dead?')
break
else:
door = input('that is not a valid choice. Do you want to enter the red door or the white door?')
我不知道如何让程序询问用户是否要重复整个过程,如果他们输入“是”就这样做
【问题讨论】:
-
围绕所有代码添加另一个while循环...然后也许将代码重构为类中的函数/方法...
-
程序风格很难用于此目的,尝试创建一个可以触发的函数以重新启动进程
标签: python loops if-statement nested adventure