红包demo

 嘿嘿,红包demo

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]))
原文地址:https://www.cnblogs.com/lgm1999/p/6132749.html