Make craps more interesting

The die_visual.py has been modified, some new funcitons have been added.

The number of dice has been changed to two.

One of them was 8 face dice.

die_visual.py

  1. import pygal
  2. from die import Die

  3. die1 = Die()
  4. die2 = Die(10)
  5. results = []

  6. for roll_num in range(10000):
  7.     result1 = die1.roll()
  8.     result2 = die2.roll()
  9.     results.append(result1+result2)

  10. #分析结果
  11. frenquencies = []
  12. for value in range(2,die1.num_sides+die2.num_sides+1):
  13.     frenquency = results.count(value)
  14.     frenquencies.append(frenquency)
  15. print(frenquencies)
  16. #绘制直方图
  17. hist = pygal.Bar()
  18. hist.title='Results of rolling one D6 1000 times'
  19. hist.x_labels = ['2','3','4','5','6','7','8','9','10',
  20.                  '11','12','13','14','15','16']
  21. hist.x_title = 'Result'
  22. hist.y_title = 'Frenquency of Result'

  23. hist.add('D6 + D10',frenquencies)
  24. hist.render_to_file('die_visual.svg')
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值