每天努力一点点,坚持下去 ------ 博客首页

Python-大乐透

import random,string

nums = set()
num = input('请输入要产生多少注:').strip()
while len(nums)!=int(num):
    before = ' '.join(sorted(random.sample([str(nember).zfill(2)for nember in range(1,33)],5)))
    back = ' '.join(sorted(random.sample([str(n).zfill(2)for n in range(1,13)],2)))
    numbers = ('前区:%s  后区:%s\n'%(before,back))
    nums.add(numbers)
with open('大乐透.txt','a+',encoding='utf-8') as fw:
    fw.writelines(nums)

 

posted @ 2020-04-07 22:23  他还在坚持嘛  阅读(1092)  评论(0编辑  收藏  举报