模拟抢红包的小功能
要求如下:
#1.红包的总金额total,发放红包的数量num
#2.每个红包的最低金额为1元,且每个红包均为整数金额
#每个红包的金额【总金额-已抢红包*1】
import numpy as np
#total:模拟发红的总金额 num:数量
def hongbao(total,num):
already=0 #已发红包初始化为0
hongbaomessage=''#定义一个空的字符串,用来存储需要输出的信息
for i in range(1,num):
hb=np.random.randint(1,total-already-(num-i)*1)
already=already+hb
hongbaomessage=hongbaomessage+str(hb)+","
hongbaomessage=hongbaomessage+str(total-already)
return hongbaomessage
total=eval(input("请输入红包的总金额"))
num=eval(input("请输入抢红包的总人数"))
result=hongbao(total,num)
print(result)