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.""" ... 

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

Oracle Database 19c DBA By Examples Installation And Administration

Authors: Ravinder Gupta

1st Edition

B09FC7TQJ6, 979-8469226970

More Books

Students also viewed these Databases questions

Question

1. Who will you assemble on the team?

Answered: 1 week ago

Question

4. Who would lead the group?

Answered: 1 week ago