Please help. this is my code and i want it to look like the image below it thank
ID: 3834886 • Letter: P
Question
Please help. this is my code and i want it to look like the image below it thanks...
This is the image link
http://i67.tinypic.com/wasv0k.jpg
This is the instructions ...
Match Coins: Create a coin toss game with two players. Each player starts with 20 coins. Rules:
each player tosses their own coin
If the coins match,
Player1 gets Player2’s coin.
If not, the Player2 gets the coin from Player1.
Whoever has the most coins wins.
In main(), create a while loop that asks to user to continue play.
In each loop, report the results … coins matched?
Total coins for each player?
The loop should toss the coins at least once.
A ‘Coin’ class is needed. The class requires:
The methods __init__(), toss(), get_sideup(), get_amount(), set_amount()
The class needs the attributes ’__amount’, initialized to 20, and ’__sideup’ initialized to one of two values, ‘Heads’ or ‘Tails’.
‘toss()’ method : generates a random value of ‘0’ or ‘1’, assigning ‘Heads’ or ‘Tails’ accordingly.
‘get_sideup()’ method : returns the current value of __sideup.
‘set_amount()’ method : passes a +1 or -1 to change __amount, depending on the results of the toss.
‘get_amount()’ method : returns the current value of __amount.
‘spend()’ method : you are in Vegas. This method ‘zero’s’ your amount and even assigns a random negative value to your amount. If the amount is zero, you get your hand slapped … just a little humor. You needn’t implement this method.
UML diagram for Coin class: (- is private, + is public)
Coin
-sideup
-amount
+__init__()
+get_amount()
+set_amount(int): should be +/-1
+get_sideup()
+toss()
Game Plan:
from coin import Coin
def main()
create two Coin objects
ask player if they want to play
while ‘y’ or ‘Y’
both players toss their coin
if both coins match
add to player1 and subtract from player2
else
add to player2 and subtract from player 1
print results of toss
ask players if they want to play
print overall results
Coin
-sideup
-amount
+__init__()
+get_amount()
+set_amount(int): should be +/-1
+get_sideup()
+toss()
7K Pytl Shell hon Layers, Channels, Paths, Undo Brushes, Tool File Edit Shel Debug options Windows Help Python 3.1.1 (r311:74483 Aug 17 2009 17:02:12 [MSc v. 1500 32 bit Intel on win32 Type copyright credits or license for more information. RESTART Do you want to continue? Player 2 Wins! Player 1 ssed a Tails and Player 2 to Heads to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Tails and Player 2 to Heads to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Tails and Player 2 to Heads to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Heads and Player 2 to Tails to ssed Do you want to continue? Player 1 wins! Player 1 ssed a Heads and Player 2 to Heads to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Heads and Player 2 to Tails to ssed Do you want to continue? Player 1 wins! ale Player 1 ssed a Heads and Player 2 to Heads to ssed Do you want to continue? Player 1 wins! Player 1 ssed a Tails and Player 2 to Tails to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Heads and Player 2 to Tails to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Heads and Player 2 to Tails to ssed Do you want to continue? Player 2 Wins Player 1 ssed a Tails and Player 2 to Heads to ssed Do you want to continue? n Player1 15 cents and Player2 25 centsExplanation / Answer
main.py
from coin import Coin
def main():
c1 = Coin()
c2 = Coin()
play = input("Do you want to continue? (y/n): ")
while play == 'y' or play =='Y':
c1.toss()
c2.toss()
if c1.get_sideup() == c2.get_sideup():
c1.set_amount(1)
c2.set_amount(-1)
print("Player 1 Wins!")
else:
c1.set_amount(-1)
c2.set_amount(1)
print("Player 2 Wins!")
print("Player1 toseed a " + c1.get_sideup() + " and Player 2 tossed " + c2.get_sideup())
play = input("Do you want to play? (y/n): ")
print("Player1 : " + str(c1.get_amount()) + "cents, Player2 : " + str(c2.get_amount()) + " cents.)
main()
coin.py
from random import randint
class Coin:
def __init__(self):
self.__amount = 20
self.__sideup = "Heads"
def toss(self):
val = randint(0, 1)
if val == 0:
self.__sideup = "Heads"
else:
self.__sideup = "Tails"
def get_sideup(self):
return self.__sideup
def set_amount(self, change):
self.__amount += change
def get_amount(self):
return self.__amount
def spend(delf):
self.__amount = 0
Seems like this was my code only, you could have asked on previous question itself for changes.
Anyway comment if something is not as you desired.
# code link: https://paste.ee/p/5HIml