所以我想制作一个文字冒险游戏,但是我无法解释这个错误,它根本无法打印某些部分,希望你们能帮助我并解释一下。我的代码如下
print("Psst... hey you are finally awake")
print("You are currently in a empty room on a chair you got caught in your adventure by a wizard in his castle")
print("There are 3 doors in front of you")
print("If you open the first door you will enter in a room full of spikes")
print("But if you open the second door you will enter in a room full of lions who didn't eat a entire month")
print("And after the third door there is a room with deadly gas")
FirstChoice = input ("Wil you choose |1| |2| or |3| ")
if FirstChoice == "1":
print("Wrong! Try again")
SecondChance = input("Will you choose |1| |2| or |3| ")
elif SecondChance == "1":
print("GAME OVER")
elif SecondChance == "2":
print("You escaped!")
elif SecondChance == "3":
print("GAME OVER")
elif FirstChoice == "2":
print("You escaped!")
使用此代码:
FirstChoice = input("Will you choose |1| |2| or |3|? ")
if FirstChoice != "2":
print("Wrong! Try again")
SecondChance = input("Will you choose |1| |2| or |3|? ")
if SecondChance != "2":
print("GAME OVER")
else:
print("You escaped!")
else:
print("You escaped!")
您必须对第二个猜测使用单独的if语句(它必须嵌套在第一个if语句内)。还请注意您的缩进。