<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hesam</title>
    <description>The latest articles on DEV Community by Hesam (@hesoom).</description>
    <link>https://dev.to/hesoom</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3411995%2F3b048fd1-f77c-467e-9421-9b6e181dcad6.jpg</url>
      <title>DEV Community: Hesam</title>
      <link>https://dev.to/hesoom</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hesoom"/>
    <language>en</language>
    <item>
      <title>Build a Hogwarts House Quiz App with Python &amp; Flask</title>
      <dc:creator>Hesam</dc:creator>
      <pubDate>Wed, 06 Aug 2025 17:55:54 +0000</pubDate>
      <link>https://dev.to/hesoom/build-a-hogwarts-house-quiz-app-with-python-flask-5401</link>
      <guid>https://dev.to/hesoom/build-a-hogwarts-house-quiz-app-with-python-flask-5401</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;h2&gt;
  
  
  Tools &amp;amp; Technologies Used
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  How It Works – The Quiz Logic
&lt;/h2&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;Here’s a simplified snippet of the core scoring logic:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Updating house score
&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;selected_house&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;

&lt;span class="c1"&gt;# After last question:
&lt;/span&gt;&lt;span class="n"&gt;winner&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;max&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;key&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;scores&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;get&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nf"&gt;redirect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;url_for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;result&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;house&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;winner&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Visual Design
&lt;/h2&gt;

&lt;p&gt;The UI is pretty simple but tries to suck you in. A quote, house colors and notable characters.&lt;br&gt;
A snippet from the &lt;code&gt;result.html&lt;/code&gt; template:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;img&lt;/span&gt; &lt;span class="na"&gt;src=&lt;/span&gt;&lt;span class="s"&gt;"{{ houses[house]['logo'] }}"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ houses[house]["quote"] }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;p&amp;gt;&lt;/span&gt;{{ houses[house]["traits"] }}&lt;span class="nt"&gt;&amp;lt;/p&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Session Management in Flask
&lt;/h2&gt;

&lt;p&gt;To keep track of answers across multiple pages, Flask sessions are our trusty sidekick:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Current house scores&lt;/li&gt;
&lt;li&gt;Selected answers per question&lt;/li&gt;
&lt;li&gt;Quiz completion status&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We clear the session on the homepage so everyone gets a fresh start every time.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Learned
&lt;/h2&gt;

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

&lt;h2&gt;
  
  
  Code
&lt;/h2&gt;

&lt;p&gt;You can find the full code here:&lt;br&gt;
&lt;a href="https://github.com/Hesoom/Hogwarts-house-sorting" rel="noopener noreferrer"&gt;🔗 GitHub – Hogwarts House Sorting Quiz&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>python</category>
      <category>flask</category>
      <category>tutorial</category>
    </item>
  </channel>
</rss>
