0% found this document useful (0 votes)
1 views

Task 1

python programs

Uploaded by

hriday.nijhawan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Task 1

python programs

Uploaded by

hriday.nijhawan
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Name 13 December 2024

Programming Project 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.

Test Plan Design


Test Number What I am testing Test Data and Expected Result
type
1 Check if the initial No input yet Display: “Press ‘R’
message is shown for Rock, ‘P’ for
Paper, or ‘S’ for
Scissors.”
2 Test user input Input: “R” Display:
(Rock) Computer’s
choice.
3 Test user input Input: “P” Display:
(Paper) Computer’s
choice.
4 Test user input Input: “S” Display:
(Scissors) Computer’s
choice.
5 Test a win (Rock Input: “R”, Display: “you
vs Scissors) Random: Scissors win”
6 Test a tie (Rock vs Input: “R”, Display: “it’s a
Rock) Random: Rock tie”
7 Test a loss (Rock Input: “R”, Display:
vs Paper) Random: Paper “computer wins”
8 Check if invalid Input: “X” (Invalid Display: Error
input) message to enter
valid input

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

else if random number == 2


computer_choice = "Paper"
else
computer_choice = "Scissors"
5. Show computer's choice
6. Compare user_choice and computer_choice to determine the winner:
if user_choice == computer_choice
Display "it’s a tie"
else if (user_choice == "R" and computer_choice == "Scissors") or
(user_choice == "P" and computer_choice == "Rock") or
(user_choice == "S" and computer_choice == "Paper")
Display "you win"
else
Display "computer wins"
7. End game

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

Scissors Computer: computer’s


random choice

Test Plan screenshots

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

print("invalid choice please choose R, P, or S.")


continue

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 will randomly assign a value of Rock, Paper or Scissors

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.

 The computer output must be shown.

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.

 It must show who won the round.

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.

 It should be tested to ensure all possible values work correctly.

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

You might also like