完整题干
输出三位数所有约数:随机生成一个三位数n,输出其所有约数。、
参考代码:
from random import *
n=randint(100,999)
print("产生的随机三位数为:",n,"其所有约数为:")
for i in range(1,n+1):
if n%i==0:
print("{:>3}".format(i),end=" ")
思考:若要将所有约数从大到小排列, 代码如何修改?
输出三位数所有约数:随机生成一个三位数n,输出其所有约数。、
参考代码:
from random import *
n=randint(100,999)
print("产生的随机三位数为:",n,"其所有约数为:")
for i in range(1,n+1):
if n%i==0:
print("{:>3}".format(i),end=" ")
思考:若要将所有约数从大到小排列, 代码如何修改?