Python 程序:求任意正整数的所有约数
n = int(input('请输入一个正整数:'))
# 找出所有约数
divisors = []
for i in range(1, n+1):
if n % i == 0:
divisors.append(i)
# 输出约数
print(f'{n}的所有约数为:{divisors}')
运行结果:
请输入一个正整数:24
24的所有约数为:[1, 2, 3, 4, 6, 8, 12, 24]
原文地址: https://www.cveoy.top/t/topic/muk9 著作权归作者所有。请勿转载和采集!