2014-12-26 77 views
-1

scenario2(結果)函數調用sget_choice3,因此它會根據用戶的選擇打印結果。雖然沒有要求輸入兩次

我想函數循環並要求輸入兩次,如果用戶選擇是0(正確的是1,0只是它的一個分支)。

s2option_list3 =['Try to force it', 'Examine the door'] 

    def sget_choice3(s2option_list3): 
     i = -1 
     while i <= 0: 
      print s2option_list3 
      choice3 = raw_input("> ") 
      for i, opt in enumerate(s2option_list3): 
       if opt in choice3: 
        i = i + 1 
        return i 
       else: 
        i = i + 2 
        return i    

      print "You need to select one of the given actions" 

def scenario2_exit(outcome): 
    print outcome 
    choice = outcomes[0] 

    if outcome in choice: 
     print "conversation" 

     res3 = sget_choice3(s2option_list3) 

     if res3 == 0: 
      print "You try to force it but without any luck. However you do notice a little button on the left corner. " 

     else: 
      print "A small panel comes out, seems to be requesting a code. " 
      print "conversation"    

    else: 
     print "conversation" 
+1

你每天都在問幾乎同樣的問題相當多。難道不是你從我們提供的答案中學到了什麼嗎? –

+0

不一樣的問題。 –

回答

1

您的問題似乎是在這一行:

for i, opt in enumerate(s2option_list3): 

當您使用enumerate這樣,它(當時-1)與枚舉的指數覆蓋您的i值(第一個選項爲0,第二個爲1)。我不知道你爲什麼試圖使用枚舉。

沒有給你如何調整你的程序太多的建議,一個簡單的解決可能是這樣的:

for opt in s2option_list3: