Middle School Code Club: Harry Potter Sorting Quiz in Python

Code your own Harry Potter house-sorting quiz in Python.  Follow along with the instruction videos below or put your Python skills to the test with your own version.

Reach out to Laura at lmiller@newcanaanlibrary.org if you need help with your code! You can share your project with me and we can review it together.

Tutorial Content

Sorting Hat Gallery

Share your finished project with me and I will post it in the Sorting Hat Gallery for everyone to try.

Introduction

We will be coding a Harry Potter sorting hat style quiz that asks users three questions and sorts them into a house. This video discusses the four houses in Harry Potter and reviews the logic of our code for the quiz.

Adding Your Questions

This video gets you started on trinket.io and walks you through how to ask your sorting questions. We cover loops, if/else statements and more!

Link to the HP Sorting Quiz Starting Project File. Click ‘Copy’ to start coding.

In the tutorial we add three questions to our quiz. You can add as many questions as you like and use your own questions. The questions used in the tutorial are:

  • What word best describes you? a. brave b. curious c. loyal d. ambitious
  • Which word would you least like to be called? a. coward b. ignorant c. selfish d. ordinary
  • Where do you best study? a. In a common room filled with lots of activity and noise b. In the library c. In a common room filled with friends helping each other study d. In a common room filled with people striving to be the best

Sorting

This is our final step! In this section, we review how to analyze the results and place the user in their house. We also discuss how to address what happens if there is no clear house winner using the random choice function.

New Canaan Library is proud serve our community during these unprecedented times.

Our team is continually working to deliver excellent digital collections, services and programs 24/7.

Your charitable support makes a real difference! Please join us by making a gift today to help us  reach our Annual Fund goal by June 30th.

THANK YOU!!