さて、私はテキストベースの冒険を作っていて、変数の金を導入しました。ストーリー オプションの 1 つで、金を拾う選択肢があるようにしようとしています。私の構文は次のようになります。
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 または CI を選択する場合は、次のように 2 回入力する必要があります。
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.