DEV Community

Cover image for Building a Harry Potter Quiz in Python
Charlotte Gale
Charlotte Gale

Posted on

Building a Harry Potter Quiz in Python

Introduction

Every developer has to start somewhere, and for me that meant turning my love for Harry Potter into code.
As part of my CS101 portfolio project, I built a simple command-line interface (CLI) quiz game that tests your knowledge of the wizarding world.
Along the way, I learned how to use Python classes, loops, and input validation to create an interactive experience right in the terminal.

Why This Project

I could have gone with Tic-Tac-Toe, or Blackjack, but I wanted something a bit more personal (and magical). A Harry Potter quiz felt like the perfect balance of fun and achievable... and let's be honest, adding house points makes everything better.

Demo

How It Works

At its heart, this quiz is built on a simple Question class in Python:

class Question:
    def __init__(self, question_text, choices, answer):
        self.question_text = question.text
        self.choices = choices
        self.answer = answer
Enter fullscreen mode Exit fullscreen mode

Each Question object stores the text, the multiple-choice options, and the correct answer.

The game then:

  1. Loops through a list of Question objects
  2. Prints the question and choices
  3. Uses input() to get the user's response
  4. Checks if the answer is correct
  5. Awards house points accordingly

The project was a great way to practice:

  • Using OOP (Object-Oriented Programming) for cleaner structure
  • Validating user input to avoid crashes
  • Keeping score across multiple rounds

Challenges and Fixes

  • "Double input" bug: At one point, my quiz was asking for the answers twice per question. Turned out I had two input lines in the method instead of one. Lesson learned: Always check for duplicate prompts.
  • Input validation: Making sure the program doesn't crash when the user types "lol" instead of "1". A simple loop with isdigit() fixed that.

What I Learned

  • Python's class system makes it much easier to manage repetitive data (like quiz questions).
  • Clean CLI design matters, even something as simple as print("=" * 40) makes the output easier to read.
  • Debugging is just as much about reading your own logic as it is about the language itself.

Future Improvements

  • Randomise the order of questions
  • Add categories (e.g. "Book Only", "Movies", "Hardcore Lore")

Try It Yourself

You can check out the full code here:
Potterhead Quiz

Clone it, run it with python quiz.py, and see how many points you can earn for your house.
Full instructions to be found in the repository's README.md.

Conclusion

This project was my first real taste of using Python to create something interactive and fun. It's not flashy, but it's functional, and gave me hands on practice with OOP, user input, and Git workflows. Most importantly, it showed me how even a small project can be a stepping stone to bigger, more complex ones.

Top comments (0)