Question
USE PYTHON CODING class Coin: #This class lets us create Coin objects showing_heads=True #By default the coin shows heads value=1#By default the coin has the
USE PYTHON CODING
class Coin:
#This class lets us create Coin objects
showing_heads=True #By default the coin shows "heads"
value=1#By default the coin has the value 1p
def show(self):
#Returns a string to incicate which face of the coin is showing
if (self.showing_heads==True):
return "Heads"
else:
return "Tails"
def turn(self):
#Turns the coin over
self.showing_heads=not self.showing_heads
Using the code shown above as a base write a code to do the following:
- Create two coin objects coin1 and coin2
- Demonstrate that they are both show() Heads
- Demonstrate that if you turn() either of them they show Tails
- Add a new member function to Coin called setValue which sets value attribute of a coin
- Add a new member function to Coin called getValue which returns the value attribute of the coin as an integer
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started