-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbetterdie.py
More file actions
52 lines (45 loc) · 1004 Bytes
/
betterdie.py
File metadata and controls
52 lines (45 loc) · 1004 Bytes
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
from random import randrange
# show_die(spots)
# Draws a picture of a die with number of spots
# indicated spots is the number of spots on the top face
def show_die(spots):
# Show the die
print("+-------+")
if value == 1:
print("| |")
print("| * |")
print("| |")
elif value == 2:
print("| * |")
print("| |")
print("| * |")
elif value == 3:
print("| *|")
print("| * |")
print("| * |")
elif value == 4:
print("| * *|")
print("| |")
print("| * *|")
elif value == 5:
print("| * *|")
print("| * |")
print("| * *|")
elif value == 6:
print("| * * * |")
print("| |")
print("| * * * |")
else:
print(" *** Error: illegal die value ***")
print("+--------+")
# Roll
# Returns a pseudorandom number in the range 1..6
def roll():
return randrange(1, 6)
# main
# Sumulates the roll of a die three times
def main():
# Roll the die three times
for i in range(0, 3):
show_die(roll())
main() # Run the program