def Tempurature(Lowest, Highest):
ok = False
while not ok:
try:
Input = int(input(print("\nEnter the Mid-Day tempurature for Day {}:".format(Counter))))
if Input >= Lowest and Input <= Highest:
ok = True
return Input
else:
print ("Please enter a valid number between {} and {}".format(Lowest, Highest))
except:
print ("Please enter a number")
所以这是我的功能,我用它来输入数字就像这样
Counter = int(1)
TempDay = array.array ("i", range(31))
TempDay[Counter] = (Tempurature(-90, 60))
然而,当我调用该函数时,以下打印
Enter the Mid-Day tempurature for Day 1:
None
任何解决方案如何摆脱&#34;无&#34;打印使输入行在&#34;:&#34;而不是在&#34;无&#34;?
的结尾答案 0 :(得分:0)
放弃print
功能内的input
来电。 input
将自动打印input
来电内的任何内容。
Input = int(input("\nEnter the Mid-Day tempurature for Day {}:".format(Counter))))
打印None
的原因是print
来电;完成后它会返回None
,因为input
会很快打印出你阻止输入的任何内容,它会打印None
,就像你打算这样做一样。
答案 1 :(得分:-1)
您正在使用None
参数调用.format。
function scope内无法使用变量Counter
。
另外,您实际上是在input()
的 return 上调用print()
,您需要将字符串传递给input()
。