DEV Community

Cover image for Build a Hogwarts House Quiz App with Python & Flask
Hesam
Hesam

Posted on

Build a Hogwarts House Quiz App with Python & Flask

If you’re learning Python and tired of building the same old boring to-do lists and calculators, themed projects can actually make coding fun. I recently whipped up a Harry Potter–inspired quiz app that sorts users into Hogwarts houses based on their answers.

This tutorial walks you through the main ideas behind building the quiz using Python and Flask. Whether you’re obsessed with wizards or just want to learn how to make a web-based quiz, this is for you.

Tools & Technologies Used

  • Python 3
  • Flask (for routing and web server)
  • HTML/CSS (with Google Fonts & custom styling)
  • Jinja2 (Flask’s built-in templating engine)
  • Session handling (to track user progress & results)

How It Works – The Quiz Logic

The quiz asks 5 multiple-choice questions. Each option is linked to one of the four Hogwarts houses: Gryffindor, Ravenclaw, Hufflepuff, or Slytherin. When a user picks an answer, we add a point to that house’s score stored in the Flask session.

Once all the questions are answered, we figure out which house got the most points and then show a result page packed with house details — including a quote, traits, famous characters, and a little design flair to make it feel Hogwartsy.

Here’s a simplified snippet of the core scoring logic:

# Updating house score
scores[selected_house] += 1

# After last question:
winner = max(scores, key=scores.get)
return redirect(url_for('result', house=winner))
Enter fullscreen mode Exit fullscreen mode

Visual Design

The UI is pretty simple but tries to suck you in. A quote, house colors and notable characters.
A snippet from the result.html template:

<img src="{{ houses[house]['logo'] }}">
<p>{{ houses[house]["quote"] }}</p>
<p>{{ houses[house]["traits"] }}</p>
Enter fullscreen mode Exit fullscreen mode

Session Management in Flask

To keep track of answers across multiple pages, Flask sessions are our trusty sidekick:

  • Current house scores
  • Selected answers per question
  • Quiz completion status

We clear the session on the homepage so everyone gets a fresh start every time.

What I Learned

  • How to use sessions for multi-step forms without losing my mind
  • Templating with Jinja2 in a real Flask project
  • Designing an interactive quiz with some basic but effective logic
  • Styling a web app so it actually looks good and fits the them

Code

You can find the full code here:
🔗 GitHub – Hogwarts House Sorting Quiz

Top comments (0)