Create Rock Paper Scissors in Python

HowToCode 123
2 min readSep 24, 2022

--

We have always played rock, and paper scissor games with our playmates. But what if your playmate is not available? Then this python programming will help you to play with rock, paper, and scissors along with the computer that you design. It is one of the most popular python project ideas for beginners to build their skills. In this program, we will use a random function to generate the unexpected output by the computer side. The user will make the first move and then the program makes one. Then a function will check the validity of the move. At last, we will display the result and ask the user to play again or not.

The python code for Rock, Paper, Scissors is as Follows:

from random import randint

#create a list of play options
t = ["Rock", "Paper", "Scissors"]

#assign a random play to the computer
computer = t[randint(0,2)]

#set player to False
player = False

while player == False:
#set player to True
player = input("Rock, Paper, Scissors?")
if player == computer:
print("Tie!")
elif player == "Rock":
if computer == "Paper":
print("You lose!", computer, "covers", player)
else:
print("You win!", player, "smashes", computer)
elif player == "Paper":
if computer == "Scissors":
print("You lose!", computer, "cut", player)
else:
print("You win!", player, "covers", computer)
elif player == "Scissors":
if computer == "Rock":
print("You lose...", computer, "smashes", player)
else:
print("You win!", player, "cut", computer)
else:
print("That's not a valid play. Check your spelling!")
#player was set to True, but we want it to be False so the loop continues
player = False
computer = t[randint(0,2)]

The output of the code is as given below:

Rock, Paper, Scissors?Paper
You win! Paper covers Rock
Rock, Paper, Scissors?Rock
Tie!

--

--

No responses yet