我该如何解决这个问题:
print 'Adventure Game'
choice_1 = raw_input('You are travelling down a long road, there is a fork in the route, one side goes to a jungle, and the other leads to a hill biome, which side do you choose? J for Jungle, H for Hill ')
if choice_1 == 'J':
print 'Jungle?, very well then'
elif choice_1 == 'H':
print 'Hill, good decision'
if choice_1 == 'J':
choice_2 = raw_input('In the jungle, a king cobra appears behind you, as you look forward, an ape leaps from a tree onto the ground. Do you take your chances with the venomous king cobra, or the enormous ape? C for cobra, A for ape ')
while choice_2 != 'A':
print 'Sorry, you were bit by the cobra and died'
print 'Please try again'
if choice_2 == 'A':
break
elif choice_2 == 'A':
print 'You were almost mauled by the ape, luckily, it fleed the scene after loosing sight of you'
如果用户选择c作为选项2,我希望它重新启动,这样每次发生这种情况时它都会从头开始
我建议对每个位置使用函数,这样就可以多次调用同一个函数或在其他函数中调用
例如:
这样,您可以快速、轻松地添加函数,并且更易于调试。
while
循环意味着如果road()
退出,它将返回到开始并重新启动road()
您可以在底部输入“是否继续?”并将其设置为变量。然后把你的整个游戏循环一段时间
相关问题 更多 >
编程相关推荐