Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | None | 0 0
  1. """
  2. 随机,额度在0.01和剩余平均值*2之间。
  3. """
  4. import random
  5. def send_money(total_yuan, num):
  6.     """send_money
  7.  
  8.    :param total_yuan: 元为单位,转成分
  9.    :param num: 人数
  10.    """
  11.     total = total_yuan * 100  # 分为单位
  12.     cur_total = 0
  13.     for i in range(num - 1):
  14.         remain = total - cur_total
  15.         money = random.randint(1, int(remain / (num - i) * 2))
  16.         cur_total += money
  17.         yield round(money / 100.0, 2)
  18.     yield round((total - cur_total) /100.0, 2)
  19.  
  20.  
  21. def test():
  22.     t = 0
  23.     for i in send_money(100, 10):
  24.         t += i
  25.         print(i)
  26.     print('sum:', t)
  27.  
  28.  
  29. if __name__ == '__main__':
  30.     test()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement