输入的if-else循环不会;我不工作;我不知道为什么


choice_five = (input("(1) fire ball  (2) cast cloak  "))
if choice_five == "1":
print("you start up your fire ball and nod at Draco. you both start to advance down the path.")
print("you turn the corner and stare face to face with two cloaked figures. they react with out hesitation.")
print("one of the cloaks throws a dark orb of energy at Draco. he swings his axe at it, but it has no effect.")
print("Draco flys backwards and slams into a tree. you throw your fire ball at the cloak, bu twhen it nears he seems to absorb it.")
print("a second to late you see the second orb flying at you. you sucumb to the tearing pain and die.")
restart_one = (input("would you like to try that again? "))
if restart_one == "yes":
choice_five
else:
print("then stay dead.")

我的重新启动命令运行良好,但不会运行第二个问题5。。。我能得到一些帮助吗。

使用while循环可以达到您的目标。在您的案例中,while循环在循环上迭代。我还在嵌套的if循环之后添加了pass语句,这样,如果您的答案等于yes,它就会通过并再次转到第一行:

while True:
choice_five = (input("(1) fire ball  (2) cast cloak  "))
if choice_five == "1":
print("you start up your fire ball and nod at Draco. you both start to advance down the path.")
print("you turn the corner and stare face to face with two cloaked figures. they react with out hesitation.")
print("one of the cloaks throws a dark orb of energy at Draco. he swings his axe at it, but it has no effect.")
print("Draco flys backwards and slams into a tree. you throw your fire ball at the cloak, bu twhen it nears he seems to absorb it.")
print("a second to late you see the second orb flying at you. you sucumb to the tearing pain and die.")
restart_one = (input("would you like to try that again? "))
if restart_one == "yes":
pass
else:
print("then stay dead.")
break

玩得开心:(

相关内容

最新更新