簡體   English   中英

范圍內的 Python 數字不起作用

[英]Python Number in Range Not Working

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: "))

我的程序只是打印“輸入一個數字:”作為它的輸出? 你能弄清楚為什么嗎? 謝謝!

您還沒有調用該函數。 輸入后,需要: 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))
# 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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM