2016-01-14 78 views
-2

每當我嘗試這個,它不起作用(輸入= 6)。它發送給我的上一個菜單,並說輸入無效。用戶輸入驗證問題

Code in Python that does not work.

def amount_of_Chests() : 
    chestCount = 0 
    amount_of_Chests_Display() 
    while chestCount <4 : 
     chestCount_string = input("Please Make Sure You Enter Enough Chests\nPlease Enter How Many Chests You Would Like (Min.4)") 
     chestCount = int(chestCount_string) 
     if chestCount < 4 : 
      print ("\nThere Are Not Enough Chests, Please Try Again.") 
      amount_of_Chests_Display() 
     if chestCount > 3 : 
      return chestCount 
      amount_of_Bandits() 
     else : 
      print ("Sorry that input is not valid. Please try Again.\n") 
+0

不是你的問題相關,但你有很多在你的代碼多餘的空格:'DEF amount_of_Chests():'應該只是'def amount_of_chests():'(也是大寫''C'是壞風格) –

+0

這就是駱駝套 –

+0

其實'thisIsCamelCasing','ThisIsStudlyCasing'和'this_is_snake_casing'。我不確定'amount_of_Chests'會是什麼;) - 無論如何,你會發現*大部分* Python代碼都符合[pep8](https://www.python.org/dev/peps/ pep-0008 /)風格指南。如果您選擇偏離標準,[它應該是一個很好的理由](https://www.youtube.com/watch?v=wf-BqAjZb8M)。 –

回答

4

無碼return語句會被執行後,所以amount_of_Bandits()將永遠不會被稱爲

+0

我應該把什麼 –

+0

@ Adam_0701:我不知道。這完全取決於你的代碼應該做什麼,而你的問題留下了很多信息。我不知道你是否打算退回,或者如果你打算調用'amount_of_Bandits()'而不是返回,或者在返回之前,或者根本不打算。 –

+0

我想返回箱子,然後去土匪數量 –