Question: Write a Python program that will flip 5 coins according to the following requirements: 1 . The program will use the following as the main

Write a Python program that will flip 5 coins according to the following requirements:
1. The program will use the following as the main script:
from coin import Coin
def main():
coins =[]
coin1= Coin(.01, "heads")
coin2= Coin(.05, "heads")
coin3= Coin(.10, "heads")
coin4= Coin(.25, "heads")
coin5= Coin(.50, "heads")
coins.append(coin1)
coins.append(coin2)
coins.append(coin3)
coins.append(coin4)
coins.append(coin5)
for c in range(5):
coins[c].flip()
for c in range(5):
print("Value: "+ coins[c].getValue())
print("Face: "+ coins[c].getSide())
if __name__=="__main__":
main()
Notice what the main script does:
It imports a Coin object.
It then declares an empty list called coins.
It creates five coins: a penny, a nickel, a dime, a quarter, and a fifty-cent piece.
Each of the coins starts out heads up on the table.
It adds each of the coins to the coins list.
It then flips each coin in the list
It then prints the value and face of each coin in the list
What you need to do:
1. You need to create a coin.py script that contains a definition for a Coin object. Notice that at a minimum, you will need to create the following methods in your class definition:
a.__init__ Constructs a new coin with the passed in value and side
b. getSide Returns the side of the coin that is up
c. flip Flips the coin so that a random heads or tails is up
d. getValue Returns the value / denomination of the coin

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!