-
Notifications
You must be signed in to change notification settings - Fork 429
Expand file tree
/
Copy pathdice.py
More file actions
60 lines (56 loc) · 1.19 KB
/
dice.py
File metadata and controls
60 lines (56 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from numpy import random # Using NumPy random
# Dice faces stored in a dictionary
dice_faces = {
1: [
"-----------",
"| |",
"| 0 |",
"| |",
"-----------"
],
2: [
"-----------",
"| |",
"| 0 0 |",
"| |",
"-----------"
],
3: [
"-----------",
"| 0 |",
"| 0 |",
"| 0 |",
"-----------"
],
4: [
"-----------",
"| 0 0 |",
"| |",
"| 0 0 |",
"-----------"
],
5: [
"-----------",
"| 0 0 |",
"| 0 |",
"| 0 0 |",
"-----------"
],
6: [
"-----------",
"| 0 0 0 |",
"| |",
"| 0 0 0 |",
"-----------"
]
}
def roll_dice():
number = random.randint(1, 7) # 1 to 6 (upper bound exclusive)
for line in dice_faces[number]:
print(line)
print(" Dice Simulator ")
while True:
roll_dice()
choice = input("Do you want to play again (y/n): ").lower()
if choice == "n":
break