设为首页收藏本站

Crossin的编程教室

 找回密码
 立即加入
楼主: crossin先生
打印 上一主题 下一主题

【每日一坑 2】 去除重复

[复制链接]

1

主题

0

好友

31

积分

新手上路

Rank: 1

楼主
发表于 2018-6-10 12:21:03 |显示全部楼层
import random

n = int(input('please enter a number:'))
m = int(input("How many numbers do you want?"))
#随机取数的函数
def wow(n, m):
    global list0
    list0 = []
    if m <= n and m >= 1:
        i = 0
        while i < m:
            list0.append(random.randint(1, n))
            i += 1
        print(list0)
    else:
        m = int(input("The number should <=n and >=1: "))
        wow(n, m)

wow(n, m)
list1 = list(set(list0))#不懂为啥自己就排序了。。。
print(list1)
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即加入

QQ|手机版|Archiver|Crossin的编程教室 ( 苏ICP备15063769号  

GMT+8, 2024-5-3 14:00 , Processed in 0.025051 second(s), 21 queries .

Powered by Discuz! X2.5

© 2001-2012 Comsenz Inc.

回顶部