QuestionQuestion

Project 1 - Rock, Paper, Scissors Game
Write a Python program rps.py that lets the user play the game of Rock, Paper, Scissors against the computer.
The program should work as follows:
You can set these constant variables at the top outside of your main function definition:
COMPUTER_WINS = 1
PLAYER_WINS = 2
TIE = 0
INVALID = 3
ROCK = 1
PAPER = 2
SCISSORS = 3
For this program 1 represents rock, 2 represents paper, and 3 represents scissors.
In your main function:
- Ask the user to choose rock, paper, or scissors like so: 'Enter 1 for rock, 2 for paper, 3 for
scissors: ' set the value to a variable called ‘player’.
- Generate a random number between 1 and 3 for the computer. Set that value to a variable called ‘computer’. 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. (Don’t display the computer’s choice yet.)
- Call your choiceString(choice) function to print the computer’s hand like so: 'Computer chose ....'
- Call your choiceString(choice) function to print the player’s hand like so: 'Player chose ....'
- Call your value returning function rockPaperScissors(computer, player) to get the result of the round between the computer and player.
- If the result is tie, print 'You made the same choice as the computer. Starting over' and repeat the process until there is no tie.
- Declare if the computer is the winner with 'The computer wins the game' or whether the player is the winner with 'You win the game' or if there was an invalid choice print 'You made an invalid choice. No winner'. If they made an invalid choice you do not need to loop through again.

Outside of your main, define the following functions:
rockPaperScissors(computer, player):
[value returning function]
This takes in integers representing the computer and player’s ‘hand’ so to speak of rock, paper, or scissors as arguments.
It returns one of the following values:
TIE
PLAYER_WINS
COMPUTER_WINS
INVALID
Using conditionals, based on the arguments passed into the function, determine which value to return based on these 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 game must be played again to determine the Winner.

choiceString(choice)
Value returning function that takes in the argument choice (the number representing rock, paper, or scissors) and return one of the following strings:
‘rock’
‘paper’
‘scissors’
‘Something went wrong’
In other words, the function returns the string value of the integer being passed in as an argument.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

# Constants
COMPUTER_WINS = 1
PLAYER_WINS = 2
TIE = 0
INVALID = 3
ROCK = 1
PAPER = 2
SCISSORS = 3

# Import random module
import random

# Main function
def main():
    player = int(input('Enter 1 for rock, 2 for paper, 3 for scissors: '))
    computer = random.randint(1, 3)
    print('Computer chose ' + choiceString(computer))
    print('Player chose ' + choiceString(player))
    result = rockPaperScissors(computer, player)
    if result == TIE:
       print('You made the same choice as the computer. Starting over')
       main()
    elif result == COMPUTER_WINS:
       print('The computer wins the game')
    elif result == PLAYER_WINS:
       print('You win the game')
    else:
       print('You made an invalid choice. No winner')
      
# rockPaperScissors function
def rockPaperScissors(computer, player):
    if computer not in [ROCK, PAPER, SCISSORS]:
       return...

By purchasing this solution you'll be able to access the following files:
Solution.PNG and Solution.py.

$27.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Python Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats