"无"打印在打印命令的末尾

时间:2015-09-17 02:03:35

标签: python arrays function

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;?

的结尾

2 个答案:

答案 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()