forked from abhaysamantni/Python_MidTerm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Midterm_Review_Q5.py
29 lines (26 loc) · 1.2 KB
/
Midterm_Review_Q5.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
# In this question, I am providing you with the driver (main) code (file Q1Driver.py) below which
#will use the class Coin that you will be writing.
import coin
def main():
# Create an object from the Coin class.
my_coin = coin.Coin()
# Display the side of the coin that is facing up by default
#(without toss).
print('This side is up:', my_coin.get_sideup())
# Toss the coin 10 times.
for i in range(10):
print('I am tossing the coin...')
my_coin.toss()
# Display the side of the coin that is facing up.
print('This side is up:', my_coin.get_sideup())
# Call the main function.
main()
# <Write a Python program to create a class called Coin
# Write the initialization function (__init__) for the class Coin. The class should have
# a private attribute sideup which can be either one of the two values: “Heads” or
# “Tails”
# Write the method toss for the class which generates a random integer using the
# function random.randint(0, 1). It sets the attribute sideup equal to Heads if
# the random integer is equal to 0 and equal to Tails if the random integer is equal to 1.
# Write a method get_sideup that returns the current value of the private attribute
# sideup.