Skip to content

Instantly share code, notes, and snippets.

@daltonpearson
Created April 15, 2020 21:21
Show Gist options
  • Save daltonpearson/15f9b97c2de150fa88db9615f56b360b to your computer and use it in GitHub Desktop.
Save daltonpearson/15f9b97c2de150fa88db9615f56b360b to your computer and use it in GitHub Desktop.
import random
from collections import Counter
def roll_dice(number_of_dice, number_of_faces):
rolls = []
for roll_number in range(1, (number_of_dice + 1)):
roll = random.randrange(1, (number_of_faces + 1))
print(f"Roll #{roll_number}: {roll}")
rolls.append(roll)
return rolls
def score_die(rolls):
occurrences = dict(Counter(rolls))
# print(occurrences)
score = 0
for value, count in occurrences.items():
# base scoring before bonuses
score += value * count
if value == 3:
# change the 3 below to whatever the 3 of a kind bonus is
score += 3
elif value == 4:
# change the 4 below to whatever the 4 of a kind bonus is
score += 4
elif value == 5:
# change the 5 below to whatever the 5 of a kind bonus is
score += 5
return score
if __name__ == "__main__":
number_of_faces = int(input("How many faces does your die have(2-20)? "))
number_of_die = int(input("How many dice will you be using (3-6)? "))
rolls = roll_dice(number_of_die, number_of_faces)
score = score_die(rolls)
print(f"Total Score: {score}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment