Building a Rock Paper Scissors Game in Python: My First Complete Python Project

Harshdeep

Learning Python by only watching tutorials can become boring very quickly. I wanted to actually build something, make mistakes, fix them, and gradually add new Python concepts to the same project.

So I decided to build a simple Rock Paper Scissors game in Python. What started as a basic game eventually became a project where I practiced many important Python concepts.

🎮 What I Built(GITHUB LINK)

The game allows a player to play Rock Paper Scissors against the computer. The computer randomly selects rock, paper, or scissors. The game continues until the player types quit.

The program also keeps track of:

  • Player score
  • Computer score
  • Number of draws
  • Overall winner

🐍 Python Concepts I Practiced

  • Variables
  • Strings
  • Lists
  • User input
  • if, elif and else
  • Comparison operators
  • Boolean operators
  • while loops
  • break and continue
  • Random numbers
  • Functions
  • Parameters and arguments
  • return
  • Scope
  • Dictionaries
  • Input validation
  • String methods such as lower() and strip()

1. Importing the Random Module

The computer needs to make a random choice. Python provides the random module for this.

import random

I created a list containing the three possible choices:

choices = ["rock", "paper", "scissors"]

Then the computer can randomly select one:

computer_choice = random.choice(choices)

For example, the computer might select rock, paper, or scissors.

2. Creating Score Variables

Next, I created variables to store the scores:

player_score = 0
computer_score = 0
draw = 0

When the player wins:

player_score += 1

When the computer wins:

computer_score += 1

And when both players choose the same option:

draw += 1

3. Creating Functions

Instead of putting all of the game logic into one large block of code, I created functions.

The first important function is decision_maker(). Its job is to determine the result of each round.

def decision_maker(user_choice, computer_choice):
    if user_choice == computer_choice:
        return "Draw!"

    elif beats[user_choice] == computer_choice:
        return "You Win"

    else:
        return "Computer Win"

The function receives two values:

  • user_choice
  • computer_choice

These are called parameters.

4. Understanding return

One of the most important things I learned was how return works.

Instead of printing the result directly inside the function, the function returns the result:

return "You Win"

I can then store that returned value:

result = decision_maker(user_choice, computer_choice)

And print it:

print(result)

The basic flow is:

User choice
     ↓
Computer choice
     ↓
decision_maker()
     ↓
   result
     ↓
  print()

5. Using a Dictionary for Game Rules

Initially, I used several long conditions to determine who won. Later, I learned that a dictionary could make the game logic much cleaner.

beats = {
    "rock": "scissors",
    "scissors": "paper",
    "paper": "rock"
}

This dictionary represents the game rules:

  • Rock beats scissors
  • Scissors beats paper
  • Paper beats rock

For example:

beats["rock"]

returns:

scissors

This allowed me to replace a long conditional statement with:

elif beats[user_choice] == computer_choice:
    return "You Win"

This made my code shorter and easier to understand.

6. Using a while Loop

The game needs to continue until the player decides to stop. For this, I used a while loop:

while True:

The player can quit the game by entering:

quit

Then the program uses break:

if user_choice == "quit":
    break

I learned that break stops the loop completely.

7. break vs continue

I also learned the difference between break and continue.

break stops the loop:

break

continue skips the current round and starts the next iteration:

continue

I used continue when the player enters an invalid choice.

if user_choice not in choices:
    print("Invalid, Please try again")
    continue

8. Input Validation

The program should not accept random values such as:

banana

I used the not in operator to check whether the input exists in my list of valid choices.

if user_choice not in choices:
    print("Invalid, Please try again")
    continue

This makes the program much more user-friendly.

9. Using lower() and strip()

Users may enter the same choice using different capitalization:

ROCK
Rock
rock

Python treats these as different strings. To solve this, I used lower():

user_choice = input("Enter Your Choice:- ").lower()

I also learned about strip(), which removes unnecessary spaces from the beginning and end of a string.

I combined both methods:

user_choice = input("Enter Your Choice:- ").lower().strip()

Now inputs such as:

   ROCK
Rock
ROCK

are converted into:

rock

10. Understanding Scope

Scope was one of the concepts I found confusing at first.

Variables created outside a function have global scope. For example:

player_score = 0

A function can normally read that variable:

def show_score():
    print(player_score)

However, modifying a global variable inside a function is different. This helped me understand the difference between local and global variables.

For this project, I kept score updates in the main game loop instead of using the global keyword.

11. Displaying the Score

I created another function to display the scores:

def show_score():
    print("Player:", player_score)
    print("Computer:", computer_score)
    print("Draw:", draw)

After the game ends, I call:

show_score()

12. Determining the Overall Winner

After the game ends, I compare the player and computer scores.

def determine_winner(player, computer):
    if player > computer:
        print("🏆 You are the overall winner!")

    elif computer > player:
        print("Computer wins!")

    else:
        print("It's a tie")

I then pass the scores to the function:

determine_winner(player_score, computer_score)

This helped me understand the relationship between function parameters and arguments.

13. Final Version of the Game

After combining everything I learned, my current version of the game is:

import random

choices = ["rock", "paper", "scissors"]

player_score = 0
computer_score = 0
draw = 0

beats = {
    "rock": "scissors",
    "scissors": "paper",
    "paper": "rock"
}


def decision_maker(user_choice, computer_choice):

    if user_choice == computer_choice:
        return "Draw!"

    elif beats[user_choice] == computer_choice:
        return "You Win"

    else:
        return "Computer Win"


def show_score():
    print("Player:", player_score)
    print("Computer:", computer_score)
    print("Draw:", draw)


def determine_winner(player, computer):

    if player > computer:
        print("🏆 You are the overall winner!")

    elif computer > player:
        print("Computer wins!")

    else:
        print("It's a tie")


print("""================================
     ROCK PAPER SCISSORS
================================

Rock
Paper
Scissors
Quit
""")


while True:

    user_choice = input(
        "Enter Your Choice:- "
    ).lower().strip()

    if user_choice == "quit":

        print("""
================================
           GAME OVER
================================
""")

        break

    if user_choice not in choices:

        print("Invalid, Please try again")

        continue

    print("Your Choice is:-", user_choice)

    computer_choice = random.choice(choices)

    print("Computer Choice:-", computer_choice)

    result = decision_maker(
        user_choice,
        computer_choice
    )

    print(result)

    if result == "You Win":

        player_score += 1

    elif result == "Computer Win":

        computer_score += 1

    else:

        draw += 1


show_score()

determine_winner(
    player_score,
    computer_score
)

14. Example Output

================================
     ROCK PAPER SCISSORS
================================

Rock
Paper
Scissors
Quit

Enter Your Choice:- ROCK
Your Choice is:- rock
Computer Choice:- scissors
You Win

Enter Your Choice:- paper
Your Choice is:- paper
Computer Choice:- paper
Draw!

Enter Your Choice:- scissors
Your Choice is:- scissors
Computer Choice:- rock
Computer Win

Enter Your Choice:- banana
Invalid, Please try again

Enter Your Choice:- quit

================================
           GAME OVER
================================

Player: 1
Computer: 1
Draw: 1

It's a tie

The computer's choices are random, so the exact output will be different every time.

15. What I Learned From This Project

This project taught me much more than simply creating a game.

I practiced:

  • Python fundamentals
  • Conditional statements
  • Loops
  • Functions
  • Parameters and arguments
  • Return values
  • Lists and dictionaries
  • Input validation
  • String methods
  • Basic scope
  • Program structure

16. Is Rock Paper Scissors Enough to Get a Python Job?

No, not by itself.

However, it is a very good first Python portfolio project. The important thing is not that the game is complicated. The important thing is that I understand the code and can explain why I wrote it.

A beginner portfolio should contain progressively more advanced projects.

Project 1: Rock Paper Scissors

Skills: Python fundamentals, functions, loops, lists, dictionaries and input validation.

Project 2: To-Do List

Add and remove tasks, mark tasks as complete, and save tasks to a file.

Project 3: Expense Tracker

Track expenses, categories, dates and monthly spending.

Project 4: API Project

Build an application that gets real-world data from an API, such as weather, movies or currency information.

Project 5: Larger Application

Eventually build a complete application involving Python, a database, APIs and a web framework.

17. What Makes a Project Valuable?

Instead of simply writing:

Made Rock Paper Scissors in Python.

A better portfolio description would be:

Developed a command-line Rock Paper Scissors game using Python. Implemented randomized computer choices, score tracking, input validation, reusable functions, dictionary-based game logic, loops and user-controlled game termination.

I would also include the source code and a README explaining how the project works.

18. My Next Steps

The Rock Paper Scissors game is only the beginning of my Python learning journey.

The next improvements I want to make include:

  • Better error handling using try and except
  • Cleaner functions
  • Better score management
  • Game statistics
  • Number of rounds
  • Replay functionality
  • Saving scores to a file
  • A better menu system
  • More advanced Python concepts

Conclusion

Building Rock Paper Scissors gave me a practical way to learn Python instead of trying to memorize the entire language first.

The project started with simple concepts and gradually introduced more advanced ideas. Every mistake became an opportunity to understand how Python actually works.

The biggest lesson I learned is:

Don't just learn Python syntax. Use Python to solve problems.

A Rock Paper Scissors game isn't enough to get a Python job, but it is a strong starting point. My goal is to continue building progressively harder projects until I can demonstrate that I can use Python to solve real-world problems.

This is just Project #1. 🚀

Post a Comment