Answered step by step
Verified Expert Solution
Link Copied!
Question
1 Approved Answer

Purpose: To practice chained if-elif-else constructs. Degree of Difficulty: Moderate. The code is not difficult, but there's a lot to read about it. The game

image text in transcribedimage text in transcribed

Purpose: To practice chained if-elif-else constructs. Degree of Difficulty: Moderate. The code is not difficult, but there's a lot to read about it. The game "rock-paper-scissors-lizard-spock" is an extension of the commonly known game "rock-paperscissors". If you're not familiar with rock-paper-scissors, click here. Rock-paper-scissors-lizard-spock adds two additional moves to the basic game. The rules are summarized both in this educational video (click to view), and the image below. The arrows indicate which move beats which. For example. the arrow from paper to Spock indicates that paper disproves Spock (if one player plays paper. and the other plays Spock. the one that played paper wins). There are 25 possible pairs of moves, so sometimes it's hard to remember them. You will write a computer program that will act as a referee. The program will ask for the moves made by the two players via console input and report which player won. To solve this problem. you'll write a function that accepts the two moves made by the players as arguments. and returns the outcome (for more detail, see below). Separately. you'll write a main program to perform the console input to request player 1's move, and player 2's move. and then call the function to determine the outcome. Note: The computer is not one of the players, the computer only determines who won given the moves that the two human players made. (a) Write a function called rock_paper_scissors_lizard_spock() that has two parameters: the first parameter is the move made by player 1 , the second parameter is the move made by player 2 . The function should return: - 1 when player 1 wins - 2 when player 2 wins - 0 if the game is tied Hint: There's a bad way and a better way to do this question. You'll know you're doing it the bad way if your program is very long. and if you are tempted to copy/paste/edit to write your code. The bad way looks at the problem from the point of view of analyzing the 25 combinations of moves by the players. The better way consists of looking at the problem from the point of view of the three possible outcomes: a win for player 1 , a win for player 2 , or a tie. Try to aim for this approach. (b) Write an appropriate docstring for your function in part (a). (c) In the main program (after the function definition), write code to prompt for, and read, the players' moves from the console. You may assume that the user always enters one of the five strings: 'rock', 'paper', 'scissors'. 'lizard', 'spock'. (d) Call the rock_paper_scissors_lizard_spock() function giving the two moves as arguments, and save its return value using a variable. (e) Use the return value to print a message to the console indicating which player won, or whether it was a tie. (f) Your program only has to referee one game. To referee another game, run the program again! What to Hand In - A file called a2q3v1.py containing your finished program, as described above. The version number (v1) portion of the file names must be changed to v2, v3 etc. each time you resubmit your assignment. Remember to include all your solution files each time you submit/resubmit your assignment

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students explore these related Databases questions

Question

What would you do?

Answered: 3 weeks ago