-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdie_roll.py
More file actions
59 lines (50 loc) · 1.48 KB
/
Copy pathdie_roll.py
File metadata and controls
59 lines (50 loc) · 1.48 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
#!/usr/bin/env python3
'''Die Rolling Simulator
A program that simulates the rolling of a die.
'''
from random import randrange
from custom_modules.get_positive_number_from_user import get_positive_num
def show_die(spots):
"""
Draws a picture of a die with the number of <spots> indicated.
<spots> is the number of spots on the top face.
"""
print('+-------+')
if spots == 1:
print('| |')
print('| * |')
print('| |')
elif spots == 2:
print('| * |')
print('| |')
print('| * |')
elif spots == 3:
print('| * |')
print('| * |')
print('| * |')
elif spots == 4:
print('| * * |')
print('| |')
print('| * * |')
elif spots == 5:
print('| * * |')
print('| * |')
print('| * * |')
elif spots == 6:
print('| * * * |')
print('| |')
print('| * * * |')
else:
print('*** Error: Illegal die spots ***')
print('+-------+')
def roll():
""" Returns a pseudorandom number in the range 1...6, inclusive """
return randrange(1, 7) # Six die-faces
def simulate_die(num_of_rolls):
""" Simulates the roll of a die <num_of_rolls>
<num_of_rolls> is a positive integer indicating the number of rolls
"""
for a_roll in range(1, num_of_rolls + 1):
show_die(roll())
if __name__ == '__main__':
simulate_die(int(get_positive_num()))