or

ask mattrab Visit www.askmattrab.com for more academic resources.

Simple program to create Rock, Paper and Scissors game in Python

Pythonlogo

This is a simple program to create a rock, paper, scissors game that we used to play in our childhood.

Note: This is a simple program and there is no graphical interference

from random import randint      # Just importing the randint function to get random values

options = ["ROCK", "PAPER", "SCISSORS"] # Creating an array that stores the values

computer = options[randint(0,2)] # Assigning value i.e. the computer chooses Rock, Paper or Scissors

player = 0 # Assigning the value to initiate the loop below

while player == 0:

player = input("Choose from 'Rock','Paper' and 'Scissors'") # Asking user for the input
if player.upper() == "ROCK": # player.upper() is used to convert the string to uppercase
if computer == "ROCK":
print("Draw!")
elif computer == "PAPER":
print("You lose!", computer, "wins against", player)
else:
print("You win!", player, "wins against", computer)


elif player.upper() == "PAPER":
if computer == "ROCK":
print("You win!", player, "wins against", computer)
elif computer == "PAPER":
print("Draw!")
else:
print("You Lose!", computer, "wins against", player)


elif player.upper() == "SCISSORS":
if computer == "ROCK":
print("You lose!", computer, "wins against", player)
elif computer == "PAPER":
print("Yow wni!", player, "wins against", computer)
else:
print("Draw!")

else: # If the user tries to input something else this runs
print("Give input correctly")

check = input("Do you want to play again? (Y/N) ") # To check if the user still wants to continue
if check.upper() == "Y":
player = 0

computer = options[randint(0, 2)] # Initializing computer a new random value for another game