Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The assignment here is to implement the game of rock, paper, scissors. The program loops through an arbitrary number of games. In each game, the

The assignment here is to implement the game of rock, paper, scissors. The program loops through an arbitrary number of games. In each game, the user specifies one of three possible plays: rock, paper, or scissors. The machine's response is chosen randomly. The two are then compared to see who won, if anyone. The rules are:

Rock beats scissors

Scissors beats paper

Paper beats rock

If both choose the same response, it is a draw (there is no winner).

The user's inputs are specified by entering a number: 1 for rock, 2 for paper, 3 for scissors. If the user enters a 4, the program should print some useful statistics, print a goodbye message, and exit. The program should reject any other inputs with an error message, but not crash.

On exit, the program computes and prints some final statistics about the play:

-number of games completed (don't count games with errors or exit);

-user wins and percentage won;

-user losses and percentage lost;

-draws and percentage draws.

Print percentages with one digit after the decimal point. Don't compute or print the statistics if no games were completed, since the percentages would involve dividing by the number of games, which is 0. Instead print a message stating no games were completed. See the sample output below.

Note that you'll need to use several of the constructs you've learned in class including a loop and if statements. You also must define at least two functions (in addition to your main() routine). For example, my version defined the following three functions, though you don't have to use these same ones:

def playName( play ): """For each possible move, return the name to print. For example, ROCK prints as 'rock'.""" ... def defeats( play1, play2 ): """Boolean valued function that returns True iff play1 defeats play2.""" ... def printStats( plays, wins, losses, draws ): """Print the statistics for the sequence of games played.""" ...

Expected output

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

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

Seven Databases In Seven Weeks A Guide To Modern Databases And The NoSQL Movement

Authors: Luc Perkins, Eric Redmond, Jim Wilson

2nd Edition

1680502530, 978-1680502534

More Books

Students also viewed these Databases questions

Question

What does this public need on this issue?

Answered: 1 week ago

Question

3.What are the Importance / Role of Bank in Business?

Answered: 1 week ago