Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This Issue been confusing to me and it's past due and can't worked anymore. but i wanted to learn more about it and see how

This Issue been confusing to me and it's past due and can't worked anymore. but i wanted to learn more about it and see how does it work. thank you

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program has 3 functions.

Function computer_play() generates a random number in the range of 1 through 3.If the number is 1, the return variable is "rock." If the number is 2, the return variable is "paper." If the number is 3, the return variable is "scissors."

Function human_play() displays a menu with options "1. rock," "2. paper," or "3. scissors" and the user inputs the number of his or her choice. The function has a validation loop that enforces an input of 1, 2, or 3. The return variable is "rock", "paper", or "scissors" based on the user's choice.

Function winner() has two parameters, computer and human. They contain the value of the player choices ("rock", "paper", or "scissors"). The function displays the choices of each player and calculates the value of the return variable ("computer", "human", or "tie") based on the following rules:

If one player chooses rock and the other player chooses scissors, then rock wins. (Rock smashes scissors.)

If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.)

If one player chooses paper and the other player chooses rock, then paper wins. (Paper wraps rock.)

If both players make the same choice, the return variable is "tie".

The main program calls computer_play() and human_play() to get the values of each choice, and then passes those choices to winner().This is done in a loop that continues as long as the return value from winner() is a tie.Once the loop is finished the program prints the name of the winner.

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 Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions