Activity 2-4

Rock, Paper, Scissors

Task

In your homework, you will be implementing the game Rock, Paper, Scissors! This activity will walk you through the process of breaking this program into concrete steps.

You will be writing your answers in plain text, so don't worry about how you will code everything just yet.

Open up a new file using Sublime and save it as FirstLast_ACT2-4.txt.

The user will be playing a game of Rock, Paper, Scissors against the computer. In your homework, you will be writing a program that accepts user input and filters it for the user's choice (as well as determining whether the user's choice is valid), computes a random choice for the computer player, and then determines the winner. Answer the questions below in your .txt file.

Step 1

You will need to accept user input. What function are you going to use to do this?

How can you store the user's input for later use throughout the program?

In other parts of the program, you will be simply printing text without requesting the user's input. How do you do this?

Step 2

You will need to find the keyword "rock", "paper" or "scissors" within the user's input. You will also need to filter out invalid input. For example, if a user inputs "rock scissors", this is considered invalid since it is unclear whether they picked "rock" or "scissors".

This is one possible formulation for your code when you check one of the keywords:

									

if _____________:


if _____________ and _____________:


For example, you will start by checking if the word "rock" is in the user's input. If the word is in there, you can use a nested if statement to further check if the word "paper" and "scissors" is not in the input. This will ensure that invalid input is not accepted. If both of these criteria is true: namely, the user's input contains the word "rock" and does not contain the words "paper" or "scissors", then you should remember the user's choice and store the word "rock" for later use.

Fill in the blanks with the code you will need to use. Alternatively, if you are unsure about the code, you can use plain English.

Note that you will also need to repeat this code structure twice more in HW2-4 for checking the keywords "paper" and "scissors".

Here are a few questions to help you think about your filtering.

What operator will you use to compare the user's input with the keywords to determine what the user chose?

You should allow for variations in capitalization and if the word choice is embedded within other words and characters. For example, "rock", "Rock!!", and "I choose ROCK" are all valid input. How will you ensure that the correct choice is extracted?

Step 3

Once you generate the computer's choice, you will need to determine the winner. Rock beats scissors, scissors beats paper, and paper beats rock. There are nine different possible outcomes, depending on the user's and computer's choice. Write out all the possible choices and outcomes.

Rock Paper Scissors
Rock
Paper
Scissors

This is one possible formulation for your code when you check one of the possible user choices:

									

if _____________:


if _____________:


elif _____________:


elif _____________:

For example, you will start by checking if the word "rock" is in the user's input. If the word is in there, you can use a nested if statement to further check if the computer chose "rock". If so, you can determine that the game is a draw. You will also need to check the other computer choices of "scissors" and "rock" in nested elif statements.

Fill in the blanks with the code you will need to use. Alternatively, if you are unsure about the code, you can use plain English.

Note that you will also need to repeat this code structure twice more in HW2-4 for comparing the user choices of "paper" and "scissors" with the possible computer choices.


Once you're done, please check off your lab with a TA or share your file with cs0030handin@gmail.com by midnight, 3/2.