我正在做一个学校项目,我必须生成一个没有重复的数字列表。扭曲是我不允许使用
random.sample()
或
random.shuffle()
. 我想我已经找到了一种方法来处理我的代码,除了我得到错误
TypeError "argument of type 'type' not iterable
. 我没能避开这件事,所以我需要一些帮助。谢谢你的帮助
代码如下:
import random
lis=[]
for i in range(5):
rand=random.randint(1,10)
if rand not in list: lis.append(rand)
print (lis)