【问题标题】:What is wrong with my function? Giving me a blank output我的功能有什么问题?给我一个空白输出
【发布时间】: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


【解决方案1】:

您的代码中没有print() 语句需要在控制台中生成输出

【讨论】:

    猜你喜欢
    • 2019-03-27
    • 1970-01-01
    • 2021-01-03
    • 1970-01-01
    • 2021-10-01
    • 2012-05-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多