import random
import matplotlib.pyplot as plt
# 1.先设定100个人,每人100块钱
p = [100] * 100
coin = 5
print(p)
ax = plt.subplot(1,1,1)
for d in range(1000):
# 2.所有人减少1块钱
for i in range(100):
p[i] = p[i] - coin
# 3.随机100次给随机1个人1块钱
for i in range(100):
lu = random.randint(0,99)
p[lu] = p[lu] + coin
p.sort()
color = []
for i in p:
if i <= 0:
color.append("red")
if i>=0:
color.append("blue")
# 4. 画图看一下分钱的情况
ax.cla()
ax.bar(range(100),p,width=0.9,color=color)
plt.title("count:"+str(d))
plt.pause(0.1)
Tina -python资金分配
最新推荐文章于 2021-05-27 18:27:27 发布