Project 3: Rock, Paper, Scissors

  < Previous  Next >

Assignment id: project3
Required Files: project3.py rubric3.txt

Due Date

See the calendar for due date.

Objectives:

Description:

Write a python script (with comments) to have a user play Rock Paper Scissors against a computer. The user chooses, "rock", "paper", or "scissors" and you can have the computer choose any of those three. The normal rules of Rock, Paper, Scissors apply here:
If the user and the computer tie (they both choose the same thing), then they continue playing that round until someone wins. Keep track of the score and report it after each win (at the end of each round). Keep playing until the user types "quit". Require that the user enter a valid option ("rock", "paper", or "scissors"), and prompt them repeatedly until they do.

Examples

The following are examples of correct execution (with the text in bold being the input from the user):
Welcome to the game of Rock Paper Scissors!
Round 1
Please enter either rock, paper, scissors or quit: rock
You entered rock
It's a tie!
Please enter either rock, paper, scissors or quit: paper
You entered paper
You won this round!
The score is: You: 1 Computer: 0

Round 2
Please enter either rock, paper, scissors or quit: scissors
You entered scissors
Sorry, the computer won this round!
The score is: You: 1 Computer: 1

Round 3
Please enter either rock, paper, scissors or quit: rock
You entered rock
It's a tie!
Please enter either rock, paper, scissors or quit: paper
You entered paper
You won this round!
The score is: You: 2 Computer: 1

Round 4
Please enter either rock, paper, scissors or quit: ROCK
You entered ROCK
Let's try again.
Please enter either rock, paper, scissors or quit: PAPER
You entered PAPER
Let's try again.
Please enter either rock, paper, scissors or quit: QUIT
You entered QUIT
Let's try again.
Please enter either rock, paper, scissors or quit: quit
You entered quit
Thanks for playing!

Submission

Submit your python script and rubric using the handin program. For handin, for this lab, type the following in a terminal window exactly as it appears:
handin  project3  project3.py  rubric3.txt
To verify your submission, type the following in a terminal window:
handin  project3

Rubric:

Points       Item
----------   --------------------------------------------------------------
_____ / 18   Meaniful comments
_____ / 10   Rock Paper Scissors game works (rock beats scissors, etc.)
_____ / 25   Script only accepts valid user input
_____ / 10   Scores correctly displayed
_____ / 25   Game continues for as many rounds as needed
_____ / 10   User input of "quit" ends the game
_____ /  2   Completed rubric (estimates for each line including hours spent)

_____ /100   Total


_____  Approximate number of hours spent

Notes

  1. Before writing any code, design a flowchart of how your algorithm will work. Then, write the comments. Then, get just the prompt working. Verify that it works. Then, work on the next step.
  2. You can use:
    import sys
    sys.exit("Optional error message")
    
    to stop executing a python script.
  3. Optionally, you can replace typing from the keyboard with the contents of a file. For example, on ranger, copy and paste the following line into a terminal window:
    python3 project3.py  <  /nfshome/hcarroll/public_html/1170/private/projects/project3-inputA.txt
    If you want to match my output exactly (and your script has the computer always choose "rock"), then run the following on ranger:
    python3  project3.py  <  /nfshome/hcarroll/public_html/1170/private/projects/project3-inputA.txt  >  outputA.txt
    diff /nfshome/hcarroll/public_html/1170/private/projects/project3-answerKeyA.txt  outputA.txt
    If the two files match exactly (which is what you want) then there should be NO output from diff. If diff shows one or more differences, fix them and run it again. To get side-by-side output (with the answer key on the left and your output on the right), replace the last line with:
    diff  --side-by-side  /nfshome/hcarroll/public_html/1170/private/projects/project3-answerKeyA.txt  outputA.txt
    For details about interpreting the output of diff, see the Using diff section on the Misc. webpage.