Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import collections
- import random
- # 1D6
- dice = [1, 2, 3, 4, 5, 6]
- # rolls a 3D6
- roll = lambda x: sum([random.choice(dice) for _ in range(x)])
- # roll 1000 times a roll 3D6
- rolls = collections.Counter([roll(3) for _ in range(1000)])
- # ratio of success and fails
- success = sum(times for face, times in rolls.items() if face < 12)
- fails = sum(times for face, times in rolls.items() if face >= 12)
- print(f'The chance of success is: {success / 10:.02f}')
- print(f'The chance of fails is: {fails / 10:.02f}')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement