Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Rock, Paper, Scissor Game (Use Functions) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program

Rock, Paper, Scissor Game (Use Functions)

Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows.

1. When the program begins, a random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen rock. If the number is 2, then the computer has chosen paper. If the number is 3, then the computer has chosen scissors. (Dont display the computers choice yet) 2. The user enters his/her choice of rock, paper, or scissors at the keyboard. 3. The computers choice is displayed. 4. A winner is selected according to the following rules: If one player (user or computer) chooses rock and the other player chooses scissors, then rock wins. If one player (user or computer) chooses scissors and the other player chooses paper, then scissors wins. If one player (user or computer) chooses paper and the other player chooses rock, then paper wins. If both players make the same choice, the game must be played again to determine the winner.

Must be Written in Python Code. MUST USE FUNCTIONS!!!

*I WROTE MY CODE WHICH IS DOWN BELOW, BUT ITS NOT RUNNING PROPERLY HELP PLEASE!!!!

import random

print("Let's Play The Game OF ROCK! PAPPER! SCISSORS!") # The title of the game

print('------------------------')

# The instructions for the game & the # key values for each choice print('To pick ROCK, enter rock') print('To pick PAPER, enter paper') print('To pick SCISSORS, enter scissors')

print('------------------------')

# This function here will generate a random number # the computer will choose from def random_number(): rpsgame = random.randint(1,3) return rpsgame

# This function is defined when the Computer # chooses 'Rock, Paper, & Scissors' against Player def computer_random_choice(rpsgame): if rpsgame == 1: computer_rps = "Rock" elif rpsgame == 2: computer_rps = "Paper" elif rpsgame == 3: computer_rps = "Scissors"

return computer_rps

# This function is defined when the User # chooses 'Rock, Paper, & Scissors' against Computer def player_random_choice(): player_rps = input('Enter the following choices, Rock, Paper, or Paper:')

return player_rps

# This function defines the possibilities of choosing # 'Rock' 'Paper' & 'Scissors' when the User plays against the computer def computerplayer_game(player_rps, computer_rps):

# 'Rock' combinations between Computer & Player if player_rps == "Rock" and computer_rps == "Rock": winner = print('Winner: Player / Winner: Computer') print('You Both Tied. Play Again')

elif player_rps == "Rock" and computer_rps == "Paper": winner = print('Winner: Computer / Loser: Player') print('You Lose. Sorry Try Again')

elif player_rps == "Rock" and computer_rps == "Scissors": winner = print('Winner: Player / Loser: Computer') print('Congradualations!!! You Won The Game')

# 'Paper'combinations between Computer & Player elif player_rps == "Paper" and computer_rps == "Paper": winner = print('Winner: Player / Winner: Computer') print('You Both Tied. Play Again')

elif player_rps == "Paper" and computer_rps == "Scissors" : winner = print('Winner: Computer / Loser: Player') print('You Lose. Sorry Try Again')

elif player_rps == "Paper" and computer_rps == "Rock" : print('Winner: Player / Loser: Computer') print('Congradualations!!! You Won The Game') #'Scissors' combinations between Computer & Player elif player_rps == "Scissors" and computer_rps == "Scissors": winner = print('Winner: Player / Winner: Computer') print('You Both Tied. Play Again')

elif player_rps == "Scissors" and computer_rps == "Rock": winner = print('Winner: Computer / Loser: Player') print('You Lose. Sorry Try Again')

elif player_rps == "Scissors" and computer_rps == "Paper" : winner = print('Winner: Player / Loser: Computer') print('Congradualations!!! You Won The Game')

return winner

def main(): player_rps = player_random_choice() rpsgame = random_number() computer_rps = computer_random_choice(rpsgame) computerplayer_game(player_rps, computer_rps) print(computer_rps, winner = computerplayer_game(player_rps, computer_rps))

main()

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

Concepts of Database Management

Authors: Philip J. Pratt, Joseph J. Adamski

7th edition

978-1111825911, 1111825912, 978-1133684374, 1133684378, 978-111182591

More Books

Students also viewed these Databases questions

Question

Define marketing concepts.

Answered: 1 week ago

Question

1 what does yellow colour on the map represent?

Answered: 1 week ago