在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
红包1 import random def redpacket(cash,person): lst=[] sum1=0 cash = cash * 100 while cash>0 and person >1: money= random.randint(1,cash) person-=1 cash-=money lst.append(money/100) sum1 += money/100 else: lst.append(cash/100) sum1 += cash/100 random.shuffle(lst) return lst,sum1 print(redpacket(100,6)) 红包2 import random def redpacket(cash,person): cash=cash*100 ret = random.sample(range(1,cash),person-1) ret.sort() ret.insert(0,0) ret.append(cash) for i in range(len(ret)-1): yield (ret[i+1]-ret[i])/100 res=redpacket(100,5) for money in res: print(money) 红包3
|
请发表评论