1 1 #产生大乐透号码 2 2 #前区 1-32,5 后区 1-12,2 3 3 #1、前区从1-32中级取5个,后区再从1-12里面取2个 4 4 #01 02 03 04 5 5 def dlt(): #生成随机大乐透号函数 6 6 all_front = [ str(num).zfill(2) for num in range(1,33) ] # 前区号码范围列表 7 7 all_back = [ str(num).zfill(2) for num in range(1,13) ] # 后区号码范围列表 8 8 front = random.sample(all_front,5) # random.sample(all_front,5)从前区序列中随机取5个元素 9 9 front.sort() 10 10 back = random.sample(all_back,2) #从后区序列中随机取2个元素 11 11 back.sort() 12 12 temp = front + back 13 13 result = ' '.join(temp) 14 14 return result 15 15 16 16 nums = set() #集合去重 17 17 num = input("请输入产生几注:").strip() 18 18 if num.isdigit(): 19 19 while len(nums)!=int(num): 20 20 haoma = dlt() 21 21 nums.add(haoma+' ') 22 22 else: 23 23 with open('dlt.txt','w') as fw: 24 24 fw.writelines(nums) 25 25 else: 26 26 print('请输入正确的数字')