Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- from collections import defaultdict
- def main():
- rolls = int(input("How many rolls? "))
- dice = int(input("How many dice? "))
- sides = int(input("How many sides per die? "))
- d = roll(dice,sides,rolls)
- h = make_histogram(d)
- display_output(d,h)
- def roll(dice,sides,rolls):
- output_dict = defaultdict(int)
- for _ in range(rolls):
- output_dict[sum([random.randint(1,sides) for _ in range(dice)])] += 1
- return output_dict
- def make_histogram(roll_array,total_symbols=80):
- total_rolls = sum([roll_array[i] for i in roll_array])
- output_array = defaultdict(int)
- for i in roll_array:
- output_array[i] = roll_array[i]*total_symbols/total_rolls
- return output_array
- def display_output(d,h):
- total_rolls = sum([d[i] for i in d])
- for i in d:
- print('{:2d}{:10d}{:8.2%} {}'.format(i,d[i],d[i]/total_rolls,"#"*int(h[i])))
- main()
Advertisement
Add Comment
Please, Sign In to add comment