forked from megliz2008/Python_Tutorial_Beginners_2019
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
executable file
·30 lines (21 loc) · 693 Bytes
/
app.py
File metadata and controls
executable file
·30 lines (21 loc) · 693 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
import random
class Dice:
def __init__(self, number_of_sides):
try:
if number_of_sides > 3:
self.number_of_sides = number_of_sides
else:
raise ValueError
except ValueError:
print('Dice must have at least 4 sides!')
# ----------------------------------------------------------------------
def roll(self, number_of_rolls):
rolls = []
for i in range(number_of_rolls):
rolls.append(random.randint(1, self.number_of_sides))
return tuple(rolls)
def main():
six_sided_dice = Dice(6)
print(six_sided_dice.roll(2))
if __name__ == "__main__":
main()