vonhee 发表于 2020-3-11 17:21:09

新手,等一个解答

2.2        用randint()方法生成取值范围为、长度为20的随机元组randTuple,并按从小到大的顺序排序对该元组进行排序,最后打印输出所有元素。

qiuyouzhi 发表于 2020-3-11 17:24:58

为什么不是列表?

zltzlt 发表于 2020-3-11 17:25:35

from random import randint
randTuple = tuple(sorted(randint(0, 100) for _ in range(20)))
print(randTuple)

jackz007 发表于 2020-3-11 17:29:50

import random

d = []
while len(d) < 20:
    x = random . randint(0 , 100)
    if x not in d:
      d . append(x)
d . sort()
print(tuple(d))

vonhee 发表于 2020-3-11 17:40:56

jackz007 发表于 2020-3-11 17:29


谢谢,

vonhee 发表于 2020-3-11 17:41:37

zltzlt 发表于 2020-3-11 17:25


谢谢
页: [1]
查看完整版本: 新手,等一个解答