2016-01-14 42 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

我想返回箱子,然后去土匪数量 –