```
def find_sums(num_dice, num_faces):
""" Given the number of dice with a given number of faces (numbered 1...num_faces),
returns a dictionary mapping all the obtainable sums (elementary events) to the number of ways to
get the sum for one throw of the dice. """
# first die
sums = dict([(i, 1) for i in range(1, num_faces + 1)])
# rest of the dice
for die in range(2, num_dice + 1):
new_sums = {}
# take each existing sum
for (total, count) in sums.items():
# and add each possible die face to it, generating new sums
for face in range(1, num_faces + 1):
temp = total + face # new sum
if temp in new_sums:
new_sums[temp] = new_sums[temp] + count
else:
new_sums[temp] = count
sums = new_sums
return sums
```

About the Author

**Are you able to help answer this sponsored question?**

Questions asked by members who have earned a lot of community kudos are featured in order to give back and encourage quality replies.

Recommended Articles