Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

  1. Match Coins: Create a coin toss game with two players. Each player starts with 20 coins. Rules:
    1. each player tosses their own coin
    2. If the coins match,
      1. Player1 gets Player2s coin.
      2. If not, the Player2 gets the coin from Player1.
      3. Whoever has the most coins wins.
    3. In main(), create a while loop that asks to user to continue play.
      1. In each loop, report the results coins matched?
      2. Total coins for each player?
      3. The loop should toss the coins at least once.

A Coin class is needed. The class requires:

  1. The methods __init__(), toss(), get_sideup(), get_amount(), set_amount()
  2. The class needs the attributes __amount, initialized to 20, and __sideup initialized to one of two values, Heads or Tails.
  3. toss() method : generates a random value of 0 or 1, assigning Heads or Tails accordingly.
  4. get_sideup() method : returns the current value of __sideup.
  5. set_amount() method : passes a +1 or -1 to change __amount, depending on the results of the toss.
  6. get_amount() method : returns the current value of __amount.
  7. 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

image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application Development And Administration

Authors: Mannino Michael

5th Edition

0983332401, 978-0983332404

More Books

Students also viewed these Databases questions