抽奖

 1 import random
 2 
 3 dictionary1={'一等奖':'HUAWEI Mate 40RS','二等奖':'华为笔记本电脑MateBook D14','三等奖':'HUAWEI MatePad 11','四等奖':'HUAWEI WATCH GT2','五等奖':'HUAWEI FreeBuds 4'}
 4 dictionary_random={'1':'一等奖','2':'二等奖','3':'三等奖','4':'四等奖','5':'五等奖'}
 5 dictionary_phone={'一等奖':'','二等奖':'','三等奖':'','四等奖':'','五等奖':''}
 6 
 7 #生成随机数,打印中什么奖
 8 def choice_random():
 9     ran=str(random.randint(1,5))
10     new_1=dictionary_random.get(ran)
11     bool1=0
12     if dictionary_phone.get(new_1)=='':
13         print('您抽中了'+new_1+''+dictionary1.get(new_1))
14         choice_update(new_1,input('请输入您的手机号码:'))
15     bool1=1
16     for key,value in dictionary_phone.items():
17         if value=='':
18             bool1=0
19             break
20     if bool1==0:#还有奖项未被抽中
21         choice_random()
22     else:
23         output()#输出函数 抽奖结束
24         #print('断点')
25 
26 def choice_update(award,phone):
27     dictionary_phone[award]=phone
28     
29 def output():
30     print('大奖获得者名单如下:')
31     for key,value in dictionary_phone.items():
32         print(key+':'+dictionary1.get(key)+'- - -'+value)
33 
34 choice_random()

 

posted @ 2021-10-28 23:05  Bruce_Sun  阅读(79)  评论(0)    收藏  举报