The Great Hall glows with floating candles. First-years whisper, robes rustle, and the enchanted ceiling reflects a stormy sky. Professor McGonagall gives you a nod. The Sorting Hat blinks awake and croaks:
“I’ll do the choosing—you’ll do the organizing.”
Your terminal (a very modern Muggle device disguised as a quill) must prepare the house rolls. We’ll collect names, preview tidy alphabetized lists, count how many students each house welcomes, and finally commit the official order to parchment. Keep your spells simple and precise—this is solemn magic.
Start by creating four empty lists to represent the Hogwarts houses: Gryffindor, Hufflepuff, Ravenclaw, and Slytherin.
Prompt the user to enter a number of student names for each house. You should ask them how many they want to enter!
You'll need to use a THE USER'S INPUT and for loop to complete this.
As they enter names, store them in the appropriate house list.
After all names are entered, print each house’s original list of students to show their unsorted order.
Sample Input/Output Screen:
What to accomplish? Focus on using sorted()
The Hat whispers, “Flippendo—a gust of order, but only a preview.”
For each house, show a temporary alphabetized list, then immediately show that the original list is unchanged
Tell the user that Hagrid needs a house count!
Use the len() function to calculate the number of students in each house.
Print a message displaying the number of students in each house, e.g., "Gryffindor has 3 students enrolled this year."
Print a message showing the TOTAL NUMBER of HOGWARTS STUDENTS
Dumbledore raises his wand. “Orbis—set the order.”
Permanently alphabetize the rolls for Gryffindor, Ravenclaw, Slytherin using .sort().
For Hufflepuff, deliberately reverse the alphabetical order (call .sort() then .reverse()), “for reasons known only to badgers.”
Print names line-by-line under each house banner—no raw list dumps.
Sometimes the Deputy Headmistress wants the roll by year instead of name.
Store entries as small records like ["Hermione Granger", 1991].
Show the difference between:
Default alphabetical by name: .sort()
Custom chronological by year: .sort(key=lambda student: student[1])