forked from zclongpop123/BlackBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwechat_money.py
40 lines (33 loc) · 1.06 KB
/
wechat_money.py
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
28
29
30
31
32
33
34
35
36
37
38
39
40
#========================================
# author: changlong.zang
# mail: zclongpop@163.com
# date: Tue, 02 Feb 2016, 18:16:16
#========================================
import random, itertools
#--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
def wechat_money(money=10.0, people=5):
'''
'''
#-
if people < 1:
return list()
if people * 0.01 > money:
return list()
#-
indexs = [i for i in range(people)]
money_list = [0.01 for i in range(people)]
overage_m = money - 0.01 * people
#-
random.shuffle(indexs)
for i in itertools.cycle(indexs):
if round(overage_m, 2) <= 0.0:
break
random_m = round(random.uniform(0.0, overage_m), 2)
money_list[i] += random_m
overage_m -= random_m
#-
return money_list
if __name__ == "__main__":
m_lst = wechat_money(10, 12)
for i, x in enumerate(m_lst):
print '第{0}个红包被领取:{1:>5} 剩余:{2}'.format(i+1, x, sum(m_lst[i+1:]))