【发布时间】:2018-03-13 07:50:02
【问题描述】:
这是比较函数:
def compare(a, b):
if a > b:
return 1
elif a == b:
return 0
else:
return -1
a=int(input('Enter first number here:'))
b=int(input('enter second number here:'))
compare(a,b)
当我运行它时,它会提示用户输入 a 和 b,但是在输入它们之后,程序什么也不做,它什么也不返回。 为什么会这样?
【问题讨论】:
-
因为您从不打印出来。试试
print(compare(a,b)) -
也许您在交互式解释器中尝试过这个?在交互式 shell 中,您执行的任何不产生
None的表达式都会被回显。但这仅发生在交互式解释器中,因为对于真正的生产脚本,您不希望所有内容都一直被回显。你需要明确写出你想出现在屏幕上的东西。