好的,所以我正在进行基于文本的冒险,并且我引入了变量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.
答案 0 :(得分:1)
假设您使用的是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")