Rock Paper Scissor game in Python

SarahDev
2 min readAug 31, 2023

I happy to help you create a Rock Paper Scissors game tutorial in Python! Here’s a step-by-step guide along with the code:

Step 1: Set Up the Game

Create a new Python file (e.g., rock_paper_scissors.py) and let's start by importing the necessary modules and defining the basic structure of the game.

import random

def main():
print("Welcome to Rock Paper Scissors!")
play_game()

if __name__ == "__main__":
main()

Step 2: Implement the Game Logic

Now, let’s add the game logic. We’ll take input from the player and generate a random choice for the computer. Then, we’ll determine the winner based on the choices.

def play_game():
choices = ["rock", "paper", "scissors"]

while True:
player_choice = input("Enter your choice (rock/paper/scissors) or 'exit' to quit: ").lower()

if player_choice == "exit":
print("Thanks for playing!")
break
elif player_choice not in choices:
print("Invalid choice. Please choose rock, paper, or scissors.")
continue

computer_choice = random.choice(choices)
print(f"Computer chose: {computer_choice}")

result = determine_winner(player_choice, computer_choice)…

--

--