不重复的列表

# 定义一个不重复的列表
import random
list= []
count= 0 # 成功放入的次数
while count<5:
    num= random.randint(1,10)
    if num not in list:
        list.append(num)
        count+=1 # 成功后计数一次
print(list)

 

posted @ 2023-07-17 17:12  胖豆芽  阅读(6)  评论(0编辑  收藏  举报