Question: Please help. this is my code and i want it to look like the image below it thanks... from random import randint class Coin(object): def
Please help. this is my code and i want it to look like the image below it thanks...
from random import randint class Coin(object): def __init__(self,__amount = 20, __sideup = "Heads"): 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 get_amount(self): return self.__amount def set_amount(self, change): self.__amount += change def spend(self): self.__amount = 0 #main() c1 = Coin() c2 = Coin() play = input("Do you want to play? (y): ") while 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: " + str(c1.get_amount()) + " and player2: " + str(c2.get_amount())) play = input("Do you want to play? (y): ")
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 Player2s 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 zeros 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 neednt 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
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 centsStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
