Python 嵌套的if语句不起作用

Python 嵌套的if语句不起作用,python,Python,好的,我正在做一个基于文本的冒险,我引入了变量gold。我正在努力使它在一个故事的选择,你有一个选择,拿起黄金。我的语法如下所示: if choice == "A": print("There is no answer. But there is 5 gold on the floor, would you like to pick it up? Type: YES or NO") yesorno = input() if yesorno == "YES": g = g + 5

好的,我正在做一个基于文本的冒险,我引入了变量gold。我正在努力使它在一个故事的选择,你有一个选择,拿起黄金。我的语法如下所示:

if choice == "A":
    print("There is no answer. But there is 5 gold on the floor, would you like to pick it up? Type: YES or NO")
yesorno = input()
if yesorno == "YES":
    g = g + 5
    print("You picked them up.",ge,"g")


elif choice == "B":
    print("Someone from a long distance away shouts: 'Shut up",name,"!'. Then the man walks away down what seems like a echoey corridor.")

elif choice == "C":
    print("Nothing happens, you are left to die.")
    sys.exit("You lost")
选择“A”很好,但如果我想选择B或C,我必须键入两次,如下所示:

Either type A, B or C to choose.
B
B
Someone from a long distance away shouts: 'Shut up g !'. Then the man walks away down     what seems like a echoey corridor.

假设您使用的是python 3,我认为问题在于缩进和未定义的变量
ge

if choice == "A":
    print("There is no answer. But there is 5 gold on the floor, would you like to pick it up? Type: YES or NO")
    yesorno = input()
    if yesorno == "YES":
        g = g + 5
        print("You picked them up.",g,"g")
elif choice == "B":
    print("Someone from a long distance away shouts: 'Shut up",name,"!'. Then the man walks away down what seems like a echoey corridor.")
elif choice == "C":
    print("Nothing happens, you are left to die.")
    sys.exit("You lost")

那么你得到的错误是什么?给出错误的选择代码B在哪里?你的意思是当结果“B”放在yesorno中时选择B会返回错误?如果有错误,请提供回溯和代码的相关部分(这意味着)你所说的代码行和错误都不在问题中。请完成你的问题!确保缩进正确。看起来
yesorno
属于choice
A
,因此它需要相同的缩进。变量ge的定义更进一步,但这就把它全部整理好了,非常感谢:)