首页 > 代码库 > 抢红包游戏

抢红包游戏

 1 #coding:utf8 2 import random 3 import sys 4 reload(sys) 5 sys.setdefaultencoding(gbk) 6 def redpacket(money_total,pople_num=1): 7     res = [] 8     if pople_num == 1: 9         res.append(money_total)10         return res11     while pople_num > 0:12         max_m = money_total*100-pople_num#为了保证每个人都有红包拿,限制了最大红包的值13         m = random.randint(1,int(max_m))14         m = m*0.0115         res.append(%.2f%m)16         money_total -= m17         pople_num -= 1 18         if pople_num == 1:19             res.append(%.2f%money_total)20             break21     return res22 23 if __name__ == __main__:24     m_total = int(raw_input(u发红包:))25     p_num = int(raw_input(u几个人抢:))26     print u 设置抢红包金额:+str(m_total)27     print u 设置抢红包的人数 :+str(p_num)28     res = redpacket(m_total,p_num)29     names = []30     while p_num > 0:31         name = raw_input(u输入你的英文大名来抢红包!: )#为什么只能输入英文大名?32         if name in names:33             print name + u 你抢过一次了把机会留给别人吧!34         else:35             n = random.randint(0,len(res)-1)36             print name+u 抢了+str(res[n])+u37             res.remove(res[n])38             names.append(name)39             p_num -= 140             print u 剩余次数: + str(p_num)

 

抢红包游戏