-
Notifications
You must be signed in to change notification settings - Fork 1
/
dice.py
29 lines (21 loc) · 842 Bytes
/
dice.py
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
# The pair of dice needed for Monopoly.
import random
class TwoDice:
def __init__(self):
self.this_throw = 0 # Total value of this throw of the dice.
self.is_a_double = False # True iff the two thrown dice match.
def roll_one_die(self) -> int:
"""Roll a single die."""
return random.randint(1, 6)
def roll_two_dice(self) -> int:
"""Roll a pair of dice."""
first_die = self.roll_one_die()
second_die = self.roll_one_die()
self.this_throw = first_die + second_die
self.is_a_double = (first_die == second_die)
return self.this_throw
def print_dice(self):
if self.is_a_double:
print('Dice throw =', self.this_throw, '(a double)')
else:
print('Dice throw =', self.this_throw)