查看一个数所有的因子及因子的和

def factor(n):
    nums = [ ]
    for i in range(1,n+1):
        if n % i == 0:
            nums.append(i)
    print(n,"的因子有:",nums)
    print("所有因子的和为: ",sum(nums))
while True:
    num = int(input("请输入 100 到 1000 之间的数"))
    if not 100 <= num <= 1000:
        print("请输入正确数值")
        continue
    factor(num)
    break


2020-06-07

posted @ 2020-06-07 11:08  CodeYaSuo  阅读(445)  评论(0编辑  收藏  举报