Skip to content

Commit c825bb9

Browse files
Merge pull request raviprakashdev#47 from SoWrongImRight/mycontribution
Add in a dice roller program that is more comprehensive, if less show…
2 parents a0e2790 + 7d7bd77 commit c825bb9

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

dice_roller.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"""The purpose of this program is to roll a quantity number of die type dice and provide the user with the results"""
2+
import random
3+
4+
die = input("What die type (default is d6): ") or "d6" #Promtps user for the type of die to roll or defaults to a six sided die
5+
quantity = input("How many (default is 1): ") or 1 #Prompts user for the number of dice to roll or defaults to 1
6+
quantity = int(quantity) #Changes the user provided information (a string) into an integer for use in the range call in the for loop.
7+
total = 0 #Set total to 0
8+
9+
#There is probably a more eliegant way to do this but I don't know how
10+
if die == "d4":
11+
sides = 4
12+
elif die == "d6":
13+
sides = 6
14+
elif die == "d10":
15+
sides = 10
16+
elif die == "d12":
17+
sides = 12
18+
elif die == "d20":
19+
sides = 20
20+
elif die == "d100":
21+
sides = 100
22+
else:
23+
print("That is not a die type")
24+
25+
for i in range(0, quantity): #Iterates through the quantity of dice to be rolled and dieplays their individual results
26+
result = (random.randint(1, sides))
27+
print(i+1, die, " = ", result)
28+
total += result
29+
print("This is the result of your roll: ", total)

0 commit comments

Comments
 (0)