# Congrats!
Here's a recap of everything we learned so far:
- Control flow is the order in which the program's code executes.
if
statement tests a condition for truth and executes the code if it is True
.
elif
clause can be added between if
and else
.
else
executes the code if none of above is True
.
- Relational operators are used to compare two values:
==
, !=
, >
, >=
, <
, <=
.
Now let's put all your learnings together to create your own quiz!
# Instructions
The Sorting Hat is a magical talking hat at Hogwarts School of Witchcraft and Wizardry. The hat decides which of the four "Houses" each freshman student goes to:
- 🦁 Gryffindor
- 🦅 Ravenclaw
- 🦡 Hufflepuff
- 🐍 Slytherin
Write a sortinghat.py program that asks the user some questions using int()
and places them into one of the Houses based on their answers:
Q1) Do you like Dawn or Dusk?
1) Dawn
2) Dusk
- If answer is equal to 1, Gryffindor and Ravenclaw both get a +1.
- Else if answer is equal to 2, Hufflepuff and Slytherin both get a +1.
- Else, output the message "Wrong input."
Q2) When I'm dead, I want people to remember me as:
1) The Good
2) The Great
3) The Wise
4) The Bold
- If the answer is 1, Hufflepuff +1.
- Else if answer is 2, Slytherin +1.
- Else if answer is 3, Ravenclaw +1.
- Else if answer is 4, Gryffindor +1.
- Else, output the message "Wrong input."
Q3) Which kind of instrument most pleases your ear?
1) The violin
2) The trumpet
3) The piano
4) The drum
- If the answer is 1, Slytherin +1.
- Else if the answer is 2, Hufflepuff +1.
- Else if the answer is 3, Ravenclaw +1.
- Else if the answer is 4, Gryffindor +1.
- Else, output "Wrong input."
Lastly, print out the house with the most points!
Hint
This is going to be the longest program you've written so far, so take it slow. And don't forget to run it every few lines.
Back