如何用Python随机产生1000个1~10000之间的整数,找出其中最大的5个三位数并输出?

如题所述

#!python3
from random import randint
l=[randint(1,10000) for i in range(1000)]
l3=[i for i in l if len(str(i))<=3]
for i in range(5):
    m=max(l3)
    print(m)
    l3.remove(m)

运行结果:

[willie@localhost zhidao]$ python3 suijishu.py 

977

967

956

941

938

[willie@localhost zhidao]$ python3 suijishu.py 

999

995

979

973

968

温馨提示:答案为网友推荐,仅供参考