codedex-分院帽
分院帽是霍格沃茨魔法学校里一顶会说话的魔法帽。它决定每个一年级新生会被分到四个学院中的哪一个:
🦁 格兰芬多
🦅 拉文克劳
🦡 赫奇帕奇
🐍 斯莱特林
int()编写一个程序,使用andinput()函数向用户提出一些问题:
Q1) Do you like Dawn or Dusk?
1) Dawn
2) Dusk
如果答案等于 1,则格兰芬多和拉文克劳都加 1 分。
否则,如果答案等于 2,赫奇帕奇和斯莱特林都加 1 分。
否则,输出消息“输入错误”。
Q2) When I’m dead, I want people to remember me as:
1) The Good
2) The Great
3) The Wise
4) The Bold
如果答案是 1,赫奇帕奇 +2。
否则,如果答案是 2,则斯莱特林 +2。
否则,如果答案是 3,则拉文克劳 +2。
否则,如果答案是 4,则格兰芬多加 2 分。
否则,输出消息“输入错误”。
Q3) Which kind of instrument most pleases your ear?
1) The violin
2) The trumpet
3) The piano
4) The drum
如果答案是 1,斯莱特林 +4。
否则,如果答案是 2,赫奇帕奇 +4。
否则,如果答案是 3,则拉文克劳 +4。
否则,如果答案是 4,则格兰芬多 +4。
否则,输出“输入错误”。
最后,打印出每个学院的得分。
奖励:如果你想更进一步,看看你能不能找出如何打印出得分最高的房子!
Gryffindor = 0
Ravenclaw = 0
Hufflepuff = 0
Slytherin = 0
print('The Sorting Hat')
# ~~~~~~~~~~~~~~~ Question 1 ~~~~~~~~~~~~~~~
print('Q1) Do you like Dawn or Dusk?')
print(' 1) Dawn')
print(' 2) Dusk')
answer = int(input('Enter answer (1-2): '))
if answer == 1:
Gryffindor = Gryffindor + 1
Ravenclaw = Ravenclaw + 1
elif answer == 2:
Hufflepuff = Hufflepuff + 1
Slytherin = Slytherin + 1
else:
print('Wrong input.')
# ~~~~~~~~~~~~~~~ Question 2 ~~~~~~~~~~~~~~~
print('Q2) When I\'m dead, I want people to remember me as:')
print(' 1) The Good')
print(' 2) The Great')
print(' 3) The Wise')
print(' 4) The Bold')
answer = int(input('Enter your answer (1-4): '))
if answer == 1:
Hufflepuff = Hufflepuff + 2
elif answer == 2:
Slytherin = Slytherin + 2
elif answer == 3:
Ravenclaw = Ravenclaw + 2
elif answer == 4:
Gryffindor = Gryffindor + 2
else:
print('Wrong input.')
# ~~~~~~~~~~~~~~~ Question 3 ~~~~~~~~~~~~~~~
print('Q3) Which kind of instrument most pleases your ear?')
print(' 1) The violin')
print(' 2) The trumpet')
print(' 3) The piano')
print(' 4) The drum')
answer = int(input('Enter your answer (1-4): '))
if answer == 1:
Slytherin = Slytherin + 4
elif answer == 2:
Hufflepuff = Hufflepuff + 4
elif answer == 3:
Ravenclaw = Ravenclaw + 4
elif answer == 4:
Gryffindor = Gryffindor + 4
else:
print('Wrong input.')
print('Gryffindor: ', Gryffindor)
print('Ravenclaw: ', Ravenclaw)
print('Hufflepuff: ', Hufflepuff)
print('Slytherin: ', Slytherin)
if Gryffindor >= Ravenclaw and Gryffindor >= Hufflepuff and Gryffindor >= Slytherin:
print('🦁 Gryffindor!')
elif Ravenclaw >= Hufflepuff and Ravenclaw >= Slytherin:
print('🦅 Ravenclaw!')
elif Hufflepuff >= Slytherin:
print('🦡 Hufflepuff!')
else:
print('🐍 Slytherin!')
本文是原创文章,采用 CC BY-NC-ND 4.0 协议,完整转载请注明来自 loekr
评论
匿名评论
隐私政策
你无需删除空行,直接评论以获取最佳展示效果
Steam卡片