标签:
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 res 11 while pople_num > 0: 12 max_m = money_total*100-pople_num#为了保证每个人都有红包拿,限制了最大红包的值 13 m = random.randint(1,int(max_m)) 14 m = m*0.01 15 res.append(‘%.2f‘%m) 16 money_total -= m 17 pople_num -= 1 18 if pople_num == 1: 19 res.append(‘%.2f‘%money_total) 20 break 21 return res 22 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])+u‘元‘ 37 res.remove(res[n]) 38 names.append(name) 39 p_num -= 1 40 print u‘ 剩余次数:‘ + str(p_num)
标签:
原文地址:http://www.cnblogs.com/zsl-3/p/5933377.html