Learn Python in 30 Days — Day 27: Mini Project – Rock Paper Scissors

Day 27: Mini Project – Rock Paper Scissors

Welcome to Day 27 of the Learn Python in 30 Days series!

Today we’re building your first complete interactive game using everything you’ve learned so far in this series. Rock Paper Scissors is the perfect mini-project: small, fun, and a brilliant way to combine variables, loops, functions, conditionals, modules, error handling, user input, and even debugging skills from Day 26.

By the end of this lesson, you’ll have a polished console game that feels like a “real program”, and a foundation you can expand later (score tracking, classes, JSON saving, etc.).

All example files for this series are available on my GitHub: Learn-Python-in-30-Days

Rock Paper Scissors

Here is a complete, clean, commented version of the game that uses everything you’ve learned so far.

rock_paper_scissors.py

import random # Day 19 - modules VALID_CHOICES = ["rock", "paper", "scissors"] def get_player_choice(): """Ask the player for a choice and return it in lowercase.""" while True: choice = input("Choose Rock, Paper or Scissors: ").strip().lower() # Day 17 – error handling mindset if choice not in VALID_CHOICES: print("Invalid choice! Try again.") continue return choice def get_computer_choice(): """Return a random choice for the computer.""" return random.choice(VALID_CHOICES) def determine_winner(player, computer): """Return 'player', 'computer', or 'draw' depending on who wins.""" if player == computer: return "draw" # Day 5–6: conditionals + logical operators if ( (player == "rock" and computer == "scissors") or (player == "scissors" and computer == "paper") or (player == "paper" and computer == "rock") ): return "player" else: return "computer" def play_round(): """Play one round of RPS and return the result.""" player = get_player_choice() # Day 3 & 7 input handling computer = get_computer_choice() # Day 19 modules + randomness print(f"\nYou chose: {player}") print(f"Computer chose:{computer}\n") outcome = determine_winner(player, computer) if outcome == "draw": print("It's a draw!") elif outcome == "player": print("You win! 🎉") else: print("Computer wins!") return outcome def main(): """Main game loop.""" print("=== Rock Paper Scissors ===") print("Type Ctrl+C or 'quit' at any time to stop.\n") scores = {"player": 0, "computer": 0, "draw": 0} while True: # Day 9 while loops result = play_round() scores[result] += 1 print("\nScoreboard:") print(f"You: {scores['player']} | Computer: {scores['computer']} | Draws: {scores['draw']}") again = input("\nPlay again? (y/n): ").strip().lower() if again not in ["y", "yes"]: print("\nThanks for playing!") break if __name__ == "__main__": main()

Try it yourself, hopefully you'll see something like that shown below: -
You can also download this example from my GitHub here and run it yourself.

Step-by-Step Breakdown: How This Uses Your Skills

1. Clean Program Structure (Day 25)

We break the game into functions:

  • get_player_choice()

  • get_computer_choice()

  • determine_winner()

  • play_round()

  • main()

This makes debugging easier (Day 26), keeps logic tidy, and matches how real software is structured.

2. Input Handling & Validation (Days 3, 5, 17)

We accept user input and validate it using a while True: loop:

if choice not in VALID_CHOICES: print("Invalid choice! Try again.")

This prevents crashes and keeps the UX smooth.

3. Randomness (Day 19)

The computer uses random.choice() to pick a move.

return random.choice(VALID_CHOICES)

4. Conditionals & Game Logic (Days 5–6)

The winner is decided with:

if player == computer: return "draw"

and rules:

(player == "rock" and computer == "scissors")

5. While Loop Game Engine (Day 9)

The entire game repeats until the user quits.

6. Dictionaries for Score Tracking (Day 12)

scores = {"player": 0, "computer": 0, "draws": 0}

Easy to access, update and display.

7. Debugging Opportunities (Day 26)

Print statements help awareness:

print(f"You chose: {player}, Computer chose: {computer}")

If something breaks later, this is exactly where you start debugging.

Next Up — Day 28 – Final Project Planning

Tomorrow, we'll pull together things we've learnt over the past 27 days into a final project.
This will run over 3 days and well build a fully working text adventure dungeon game.

All example files for this series are available on my GitHub: Learn-Python-in-30-Days
You can see the full series here Learn Python in 30 Days series!

Hope you have enjoyed this post, thanks Matty

Comments

Popular posts from this blog

6502 - Part 2 Reset and Clock Circuit

Math Behind Logic Gates

Building a 6502 NOP Test