范围内的Python数字不起作用

时间:2017-10-01 01:40:25

标签: python range

def def range_test(num):
  if 1 < num < 550  :
    return( "{:d} is in range.".format(num))
  else:
    return("The number you entered is outside the range!")
num = int(input("Enter a number: "))

我的程序只打印&#34;输入一个数字:&#34;它的出局? 你能搞清楚为什么吗? 谢谢!

2 个答案:

答案 0 :(得分:1)

你还没有调用这个函数。输入后,您需要:range_test(num)来调用该函数。如果要打印输出,还需要打印返回值。

完整的程序应该是:

def range_test(num):
  if 1 < num < 550  :
    return( "{:d} is in range.".format(num))
  else:
    return("The number you entered is outside the range!")
num = int(input("Enter a number: "))
print(range_test(num))

答案 1 :(得分:-1)

# manipulated code given below. it is working perfectly
def range_test(num):
   if 1 < num < 550  :
       return( "{:d} is in range.".format(num))
   else:
       return("The number you entered is outside the range!")

num = int(input("Enter a number: "))
s1=range_test(num)
print"%s"%(s1)
相关问题