Task 1
Task 1
Allow the user to play 1 game of Rock, Paper, Scissors against the
computer.
The user must press enter a key to select their choice (R, P or S)
The computer will randomly assign a value of Rock, Paper or Scissors
The computer output must be shown.
It must show who won the round.
It should be tested to ensure all possible values work correctly.
Pseudocode
1. Show a message to the user: "Press 'R' for Rock, 'P' for Paper, or 'S' for
Scissors."
2. Read user's input and store it in variable called user_choice
3. Generate a random number between 1 and 3
4. Assign computer's choice based on the random number:
if random number == 1
computer_choice = "Rock"
Page 1 of 5
Name 13 December 2024
Test Plan
Test Number What I am Test Data and Expected Actual
testing type Result Result
1 User chooses User input: Output: “its a “its a tie!”
Rock (Tie) “R”, tie!”
Computer:
“R”
2 User wins User input: Output: “you “you win”
(Rock beats “R”, win”
Scissors) Computer:
“S”
3 Computer User input: Output: “the “the
wins (Rock “R”, computer wins computer
loses to Computer: the game” wins the
Paper) “P” game”
4 Invalid input User input: Output: “invalid
handling “X” (invalid “invalid choice choice
character) please choose please
R, P, or S.” choose R, P,
or S.”
5 Computer’s User input: Output “the
choice is “R”, includes “the computer
displayed Computer: computer picked: R”
random picked: ”
6 Valid input: User input: Output
user chooses “S”, depends on
Page 2 of 5
Name 13 December 2024
Project Code
import random
choices = ['R', 'P', 'S']
while True:
user_choice = input("Enter your choice (R, P, S): ")
if user_choice not in choices:
Page 3 of 5
Name 13 December 2024
computer_choice = random.choice(choices)
print(f"the computer picked: {computer_choice}")
if user_choice == computer_choice:
print("its a tie!")
elif (user_choice == 'R' and computer_choice == 'S') or \
(user_choice == 'P' and computer_choice == 'R') or \
(user_choice == 'S' and computer_choice == 'P'):
print("you win")
else:
print("the computer wins the game")
Evaluation
<under each bullet point state whether you achieved it, how you achieved it and
whether you could improve it in any way>
Allow the user to play 1 game of Rock, Paper, Scissors against the
computer.
The program allows the user to play a single game of Rock, Paper, Scissors against
the computer. This was achieved by putting in a loop that enables the user to input
their choice and have it compared against a random choice generated by the
computer. However, the game currently runs continuously due to the while loop, and
the user can’t exit after one round unless they stop the program. An improvement
would be to add an option for the user to quit after round, such as a question asking,
“Do you want to play again? (Y/N).”
The user must press enter a key to select their choice (R, P or S)
The user is asked to press a key to select their choice of R, P, or S, and this input is
validated to check only the correct options are accepted. Invalid inputs ask the user
to try again with a correct input. This works as intended, but it could be improved by
providing more detailed instructions, explaining what each letter represents (e.g.,
“Press ‘R’ for Rock, ‘P’ for Paper, ‘S’ for Scissors”). This would make the game easier
to understand.
The computer’s choice is randomly set as either Rock, Paper, or Scissors using the
random.choice() function. This creates a fair game for the user.
Page 4 of 5
Name 13 December 2024
The program displays the computer’s choice after the user makes their selection.
This was put in using a formatted string, which outputs the computer’s pick. While
this works well, the output could be improved by showing the full names of the
choices (e.g., “Rock” instead of “R”) to make the game more easy to understand.
The game displays the result of each round, whether it’s a tie, a user win, or a
computer win. This is done using conditional statements that compare the user’s
input against the computer’s choice. The result display is simple and meets the
requirements, but it could be improved by including a score counter to track how
many rounds each side has won, especially if the game is extended to multiple
rounds.
The program was tested to ensure it works correctly for all valid inputs and
outcomes.
Overall, the program meets its objectives and functions. Improvements in user
interaction, testing, and result display could further improve the program.
Page 5 of 5