【发布时间】:2018-02-19 16:57:17
【问题描述】:
def get_nearest_multiple(minnum, factor):
"""
function get_nearest_multiple will calculate the nearest multiple that is greater than the min. value,
Parameters are the minimum value and factor,
Will return the ans - the nearest multiple
"""
ans = 0
x = 1
while ans < minnum:
if minnum == 0:
ans = 0
else:
ans = x * factor
x += 1
return ans
get_nearest_multiple(0, 1)
if __name__ == '__main__':
get_nearest_multiple(0, 1)
似乎无法弄清楚为什么我的函数没有打印出任何东西。输出甚至不会显示为错误。只是空白。
【问题讨论】:
-
哪一行应该打印一些东西?
-
正确缩进函数,并执行 print(get_nearest_multiple(0, 1))
-
此外,在这种情况下,您的 while 循环返回 None,因此您应该检查您的逻辑。
标签: python-3.x function math output