每當我嘗試這個,它不起作用(輸入= 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")
不是你的問題相關,但你有很多在你的代碼多餘的空格:'DEF amount_of_Chests():'應該只是'def amount_of_chests():'(也是大寫''C'是壞風格) –
這就是駱駝套 –
其實'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)。 –