现在我在Mac上使用vim。运行文件时如何输入参数?
def isPositive(num1):
pos = False
if num1 > 0:
pos = True
return pos
else:
pos = False
return pos
答案 0 :(得分:1)
number = input("Enter a number: ")
number = int(number)
def isPositive(num1):
pos = False
if num1 > 0:
pos = True
return pos
else:
pos = False
return pos
isPositive(number)
输入命令允许您在运行文件时输入字符串。第二行将该变量转换为整数,以便可以在函数内部的if语句中使用它。然后在底部,使用数字作为参数调用该函数。