-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathcoin.py
More file actions
30 lines (21 loc) · 689 Bytes
/
coin.py
File metadata and controls
30 lines (21 loc) · 689 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
# The Coin class simulates a coin that can
# be flipped.
class Coin:
# The __init__ method initializes the
# __sideup data attribute with 'Heads'.
def __init__(self):
self.__sideup = 'Heads'
# The toss method generates a random number
# in the range of 0 through 1. If the number
# is 0, then sideup is set to 'Heads'.
# Otherwise, sideup is set to 'Tails'.
def toss(self):
if random.randint(0, 1) == 0:
self.__sideup = 'Heads'
else:
self.__sideup = 'Tails'
# The get_sideup method returns the value
# referenced by sideup.
def get_sideup(self):
return self.__sideup