-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path15_sorting_hat.py
More file actions
94 lines (91 loc) · 2.67 KB
/
15_sorting_hat.py
File metadata and controls
94 lines (91 loc) · 2.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
''' Challenge: The Sorting Hat
Objective: Develop an interactive quiz with a point system to sort the user into one of four categories based on their answers.'''
# Sorting hat
#House initilization
gryffindor = 0
hufflepuff = 0
ravenclaw = 0
slytherin = 0
print("Welcome! The Sorting Hat will now determine your house.")
print("---")
# --- Q1 ---
print("Q1) Do you like Dawn or Dusk?")
print("a) Dawn")
print("b) Dusk")
# Use .lower() to make the input case-insensitive (e.g., 'A' is treated as 'a')
answer = input("Enter your answer (a or b): ").lower()
if answer == 'a':
print("Gryffindor and Ravenclaw both get a +1.")
gryffindor += 1
ravenclaw += 1
elif answer == 'b':
print("Huffelpuff and Slytherin both get a +1.")
hufflepuff += 1
slytherin += 1
else:
print("Input not recognized.")
print("---")
# --- Q2 ---
print("Q2) When I'm dead i want people to remember me as:")
print("a) The Good")
print("b) The Great")
print("c) The Wise")
print("d) The Bold")
answer = input("Enter your answer (a, b, c, or d): ").lower()
if answer == 'a':
print("Hufflepuff +2")
hufflepuff += 2
elif answer == 'b':
print("Slytherin +2")
slytherin += 2
elif answer == 'c':
print("Ravenclaw +2")
ravenclaw += 2
elif answer == 'd':
print("Gryffindor +2")
gryffindor += 2
else:
print("Input not recognized for Q2.")
print("---")
# --- Q3 ---
print("Q3) Which kind of instrument most pleases your ear?")
print("a) The violin")
print("b) The trumpet")
print("c) The piano")
print("d) The drum")
answer = input("Enter your answer (a, b, c, or d): ").lower()
if answer == 'a':
print("Slytherin +4")
slytherin += 4
elif answer == 'b':
print("Hufflepuff +4")
hufflepuff += 4
elif answer == 'c':
print("Ravenclaw +4")
ravenclaw += 4
elif answer == 'd':
print("Gryffindor +4")
gryffindor += 4
else:
print("Input not recognized for Q3.")
print("---")
# --- Final Sorting ---
print("Calculating final house...")
# Create a dictionary to easily find the house with the max score
house_scores = {
"Gryffindor": gryffindor,
"Hufflepuff": hufflepuff,
"Ravenclaw": ravenclaw,
"Slytherin": slytherin
}
# Find the house with the maximum score
# max(iterable, key=function) finds the item that has the max value
# when the function is applied (in this case, the score of the house)
final_house = max(house_scores, key=house_scores.get)
print(f"\nYour House Scores:")
print(f" Gryffindor: {gryffindor}")
print(f" Hufflepuff: {hufflepuff}")
print(f" Ravenclaw: {ravenclaw}")
print(f" Slytherin: {slytherin}")
print("\n**The Sorting Hat has decided...**")
print(f"**Your house is... {final_house.upper()}!**")