Rock Paper Scissor Game in Python
Rock Paper Scissor Game in Python
Introduction
Let's create a simple Rock-Paper-Scissor command-line game without using any third-
party game libraries like PyGame. The player will initially have the option to choose either
Rock, Paper, or Scissors in this game. The winner is chosen in accordance with the game's
rules after the computer has made a random selection from the last two alternatives.
Objective
To defeat the opponent by choosing a weapon that defeats their choice according to the
following rules: Rock smashes (or breaks or blunts) scissors (rock wins), scissors cut paper
(scissors win), and paper covers rock (paper wins).
System Requirements
● Python installed
Implementation:
In the following implementation, the first rule states that "Rock vs Paper -> Paper Wins."
which means that if a player chooses rock and plays against an opponent who selects paper,
paper will win. The code then proceeds to state that "Rock vs Scissor -> Rock Wins,"
indicating that rock prevails when played against scissors. The last line of code states "Paper
vs Scissor -> Scissor Wins," proving that when playing scissors versus paper, scissors will
win. The program summarizes the winning rules of the Rock, Paper, Scissors game as
follows: "Rock vs Paper -> Paper Wins, Rock vs Scissor -> Rock Wins, Paper vs Scissor ->
Scissor Wins." Moving forward, the code prompts the user to decide and determines the input
value to assign it a corresponding choice: "Rock" if the choice is 1, "paper" if it is 2, or
"scissor" if it is 3. The code then asks the user for their computer turn and randomly generates
a number between 1 and 3 to represent the computer's choice. This process continues until the
computer's choice matches the user's choice. Once the computer selects rock, the code
outputs both options, indicating what happened during the game. The user is prompted to
choose among the options of rock, paper, or scissors, and the code randomly selects one of
these alternatives to represent the computer's turn. The user's selection and the computer's
selection are then printed. Finally, the code cycles back to provide the user with another
option to continue playing.
Input:
import random
while True:
print("Enter choice \n 1 for Rock, \n 2 for paper, and \n 3 for scissor \n")
if choice == 1:
choice_name = 'Rock'
elif choice == 2:
choice_name = 'paper'
else:
choice_name = 'scissor'
# of random module
comp_choice = random.randint(1, 3)
# looping until comp_choice value
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice_name = 'Rock'
elif comp_choice == 2:
comp_choice_name = 'paper'
else:
comp_choice_name = 'scissor'
if choice == comp_choice:
result = "paper"
result = "Rock"
else:
result = "scissor"
if result == Draw:
if result == choice_name:
print("<== User wins ==>")
else:
ans = input().lower
if ans == 'n':
break
print("Enter choice \n 1 for Rock, \n 2 for paper, and \n 3 for scissor \n")
if choice == 1:
choice_name = 'Rock'
elif choice == 2:
choice_name = 'paper'
else:
choice_name = 'scissor'
# print user choice
# of random module
comp_choice = random.randint(1, 3)
comp_choice = random.randint(1, 3)
if comp_choice == 1:
comp_choice_name = 'Rock'
elif comp_choice == 2:
comp_choice_name = 'paper'
else:
comp_choice_name = 'scissor'
if choice == comp_choice:
result = Draw
result = "paper"
result = "Rock"
else:
result = "scissor"
if result == Draw:
if result == choice_name:
else:
ans = input().lower
if ans == 'n':
break
# after coming out of the while loop
Output:
Conclusion
Hence, we have successfully built the Python application that allows us to play the rock,
paper, scissor game in Python which is a classic and nostalgic game and sometimes acts as a
deciding factor in performing any activity in python programming language.