Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please Help!! python; Match Coins: Create a coin toss game with two players. Each player starts with 20 coins. Rules: each player tosses their own

please Help!! python;

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

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

Step: 3

blur-text-image

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago