给定一个int类型的数字123,要求编写一个函数,返回1+2+3

def sum(num: int) -> int:
    res = 0
    while num != 0:
        res += num % 10
        num //= 10
    return res


print(sum(789))

  

posted @ 2020-05-21 16:48  hchan  阅读(351)  评论(0)    收藏  举报