编程随机抢红包的原理,微信抢红包的随机大小是怎么实现的。请简单模拟微信拼红包发放功能。
import random
dic={}
lis = ['KeLan','Monkey','Dexter','Superman','Iron Man','Robin']
def redpacket(cash,person,index):
if cash>0 and person !=1:
n = round(random.uniform(0.01,cash-(0.01*person)),2)
dic[lis[index]] = n
print(str(n).ljust(4,"0"))
person-=1
cash-=n
index+=1
redpacket(cash,person,index)
else:
dic[lis[index]]=round(cash,2)
print(str(cash).ljust(4,"0"))
redpacket(10,len(lis),0)
print (dic)
print ("手气最佳:",max(dic.items(),key=lambda x:x[1]))
分类求和类型,输入n个数,分别求大于0,小于0,等于0的个数