查看一个数所有的因子及因子的和
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
本文来自博客园,作者:CodeYaSuo,转载请注明原文链接:https://www.cnblogs.com/hany-postq473111315/p/13059879.html