python解法

明明的随机数

http://www.nowcoder.com/questionTerminal/3245215fffb84b7b81285493eae92ff0

while True:
    try:
        count = int(input())
        numbers1 = [int(input()) for x in range(count)]
        result1 = sorted(set(numbers1))

        for i in result1:
            print(i)


    except:
        break
全部评论
def function(N): result = [] for i in range(int(N)): flag = True while flag: s = input() if s.isdigit() and 1 <= int(s) <= 500: result.append(int(s)) flag = False else: continue #去重 result1 = list(set(result)) result1.sort() for j in result1: print(j) XX = True while XX: N = input() if N.isdigit() and 1 <= int(N) <= 1000: function(N) XX = False else: continue
1 回复 分享
发布于 2022-04-19 02:07
import random while True: try: n=int(input("请输入想要生成的随机数的个数(个数在1到1000个的范围内):")) set1=set({}) for i in range(n): a=random.randint(1,500) set1.add(a) nums=list(set1) for j in nums: print(j) nums.sort() except: break import random while True: try: n=int(input("请输入想要生成的随机数的个数:")) list=[] for i in range(n): b=random.randint(1,500) list.append(b) unique=set(list) list=list(unique) list.sort() for j in list: print(j) except: break 这两个方法挺好的,但是就是不知道怎么清除上一次产生的数据。
点赞 回复 分享
发布于 2022-06-30 08:49
看着华丽,实际上漏洞百出
点赞 回复 分享
发布于 2022-04-19 02:07

相关推荐

牛客nb666号:见天才的门槛罢了查看图片
点赞 评论 收藏
分享
评论
15
6
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务