失败告终
以下是repo地址:
https://github.com/xiaoyue2019/redpag
以下是关键代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
| def generate_red_bag(remain_money,remain_red_bag): """ 剩余金额\n 剩余红包数 """ if remain_money <= 0: exit("出错,剩余红包金额为0") if remain_red_bag == 1: return round(remain_money,2) water_bottom = 0.01 water_top1 = round(remain_money / remain_red_bag * 2,2) water_top2 = round(remain_money - round(water_bottom*(remain_red_bag-1),2),2) water_top = min(water_top1,water_top2)
water_radom = round(random.uniform(water_bottom,water_top),2) water_remainder = round(water_top % water_radom,2)
if water_remainder > water_bottom: current_money = water_radom else: current_money = water_bottom
return current_money
|