Skip to content

Instantly share code, notes, and snippets.

@stephengruppetta
Created August 20, 2023 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stephengruppetta/1275f1c0e816497c6445fc258250f8b5 to your computer and use it in GitHub Desktop.
Save stephengruppetta/1275f1c0e816497c6445fc258250f8b5 to your computer and use it in GitHub Desktop.
# making_magic.py
from hogwarts_magic import Student, House
# Three houses are commented just for the purpose of
# "rigging" the sorting hat's selection
houses = [
House("Gryffindor", "Godric Gryffindor", ["scarlet", "gold"], "lion"),
# House("Hufflepuff", "Helga Hufflepuff", ["yellow", "black"], "badger"),
# House("Ravenclaw", "Rowena Ravenclaw", ["blue", "bronze"], "eagle"),
# House("Slytherin", "Salazar Slytherin", ["green", "silver"], "serpent"),
]
harry = Student("Harry Potter", "stag", 1980)
hermione = Student("Hermione Granger", "otter", 1979)
ron = Student("Ron Weasley", "jack russell terrier", 1980)
harry.assign_house_using_sorting_hat(houses)
print(harry.house)
# Gryffindor
hermione.assign_house_using_sorting_hat(houses)
print(hermione.house)
# Gryffindor
ron.assign_house_using_sorting_hat(houses)
print(ron.house)
# Gryffindor
# A few checks…
print(harry.house.members)
# [
# Student('Harry Potter', 'stag', 1980),
# Student('Hermione Granger', 'otter', 1979),
# Student('Ron Weasley', 'jack russell terrier', 1980)
# ]
print(harry.house is ron.house)
# True
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment