2013-10-19 140 views
-3

好吧,所以我正在做一個基於文本的冒險,我已經介紹了可變的黃金。我試圖在故事選項之一中選擇黃金。我的語法如下:嵌套如果語句不起作用

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必須輸入他們的兩倍,因爲它顯示在這裏:

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. 
+1

有啥你的錯誤,並哪來的的choise B碼,讓錯誤 –

+0

你的意思是選擇B時的當T他的結果「B」被放置在yesorno返回一個錯誤? – RyPeck

+0

如果有錯誤提供回溯和代碼的相關部分(它意味着[SSCCE](http://www.sscce.org/)) – zero323

回答

1

假設你正在使用蟒蛇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") 
+0

變量ge被進一步定義了,但是這個排序全部結束了,非常感謝:) – Jonathan

+0

那麼如果它對你有效,你能接受這個答案嗎? –