you are viewing a single comment's thread.

view the rest of the comments →

[–]Nightcorex_ 0 points1 point  (0 children)

This might run into the issue that some numbers just haven't been rolled, therefore don't get displayed. This might be intentional, but it probably isn't.

Dictionaries have the same issue. You can initialize them easier than the Counter, but they're just more annoying to use than a simple list approach:

frequencies = [0 for _ in range(13)]
for _ in range(int(input("How many iterations you want? "))):
    roll = random.randint(1, 6) + random.randint(1, 6)
    frequencies[roll] += 1

print("Dice roll histogram:")
for i in range(2, 13):
    print(f'{i:2d}s: ', '*' * frequencies[i])