python 语言编写抽奖小程序

和男朋友约会不知道去哪玩了?中午不知道吃啥了?需要抽奖了?来编写一个抽奖小程序
import random
#输入一个抽奖池~~~~
peopledict={}
while 1:
    try:
        name,num = raw_input("please input name and num,split,").split(",")
        peopledict[num]=name
    except:
        break
print peopledict

#抽奖结果
resultdict={}
#请输入抽奖次数
try:
    num = int(raw_input("please input num:"))
except:
    print "input error"

#进行抽奖啦啦啦
while num>0:
    result = random.choice(peopledict.keys())
    resultdict[result]=peopledict[result]
    #防止一个恶心的人被连续中奖两次!!!
    del peopledict[result]
    num-=1

print resultdict.values()

猜你喜欢

转载自blog.csdn.net/qq_30758629/article/details/79372520