# CECS 277 – Lab 2 – Functions solution

\$30.00

Original Work ?

5/5 - (1 vote)

## Rock-Paper-Scissors

Write a program that allows a user to play Rock-Paper-Scissors against the computer. Have the
program keep score of how many times each has won a round. Your program should have a
main method that has a loop that repeats the game until the user chooses to quit. Display the
final score before exiting.

Write the following functions:
1. weapon_menu() – Asks the user to input their choice: (R)ock, (P)aper, (S)cissors,
or (B)ack. Checks user input for validity and then returns the inputted value.
2. comp_weapon() – Randomly chooses the computer’s throw and returns an “R”,
“P”, or “S”.

3. find_winner(player, comp) – Passes in the two weapons (R, P, or S),
displays the throws, compares the two weapons and displays the result and returns
who is the winner of that round (0=Tie, 1=Player, 2=Computer).
a. Rock crushes Scissors
b. Scissors cuts Paper
c. Paper covers Rock

4. display_scores(player, comp) – Displays the scores.
Example Output (user input is in italics):
1. Play game
2. Show Score
3. Quit
1
R. Rock
P. Paper
S. Scissors
B. Back
P
You chose Paper
Computer chose Paper
Tie
R. Rock
P. Paper
S. Scissors
B. Back
S
You chose Scissors
Computer chose Rock
Computer wins
R. Rock
P. Paper
S. Scissors
B. Back
B
1. Play game
2. Show Score
3. Quit
2
Player = 0
Computer = 1
1. Play game
2. Show Score
3. Quit
3
Final Score:
Player = 0
Computer = 1

Notes:
1. You can use the check_input module provided on Canvas to check the user’s input in the
2. Use the random module to randomly choose the computer’s weapon.
3. Please do not use any lists or global variables. Please pass all necessary values as

4. Do not create any extra functions or add any extra parameters.
5. Please read through the Coding Standards document provided on Canvas for guidance on
6. Use docstrings to document each of your five functions. Document all arguments and
return values.

7. Place your name, the date, and a brief description of the program in a comment block at

9. Thoroughly test your program before submitting/demoing.
a. Make sure each of your functions returns the correct value.
b. Make sure the computer’s throw returns a randomly assigned weapon choice.
c. Make sure that the correct winner is returned given the rules.
d. Make sure that the points are awarded to the correct player after winning a round.
e. Make sure that the points displayed are correct.
f. Make sure that the game doesn’t go back to the main menu until the user chooses
to go back.
g. Error check all user input (1, 2, 3 on the main menu, and R, P, S, B on the weapon