我用python做了一个选择题,有一部分不起作用
我做了一个选择题,允许用户在每个问题上得到总共3个提示,如果他想要的话。因此,我在提示部分中创建了if/elif/else语句,但当我运行代码并键入h时,它只是说我把问题搞错了,而没有提供提示。这是我的密码:我用python做了一个选择题,有一部分不起作用,python,Python,我做了一个选择题,允许用户在每个问题上得到总共3个提示,如果他想要的话。因此,我在提示部分中创建了if/elif/else语句,但当我运行代码并键入h时,它只是说我把问题搞错了,而没有提供提示。这是我的密码: # POINTS score = 0 # HINTS hint = 0 #QUESTIONS while True: for t in trivia: answer = input(t["question"] + "\n\nAnswer:
# POINTS
score = 0
# HINTS
hint = 0
#QUESTIONS
while True:
for t in trivia:
answer = input(t["question"] + "\n\nAnswer: ").upper()
if answer == t["answeris"]:
print("Excellent!\n")
score = score + 10
elif answer == "h":
hint += 1
if hint > 3:
print("Sorry! You used all the hints.\n")
userhint1 = input("Answer: ")
if userhint1 == t["answeris"]:
print("Excellent!\n")
score = score + 10
else:
print("Oops! You got it wrong. The answer is " + t["answeris"] + ".")
userhint2 = input(t['hint'] + "there is " + {3 - hint} + "hint(s) left. * \n" + "\nAnswer: ").upper()
if userhint2 == t["answeris"]:
print("Excellent!\n")
score = score + 10
else:
print("Oops! You got it wrong. The answer is " + t["answeris"] + ".")
else:
print("Oops! You got it wrong. The answer is " + t["answeris"] + ".")
有人能告诉我我做错了什么吗?您输入的字符串已转换为大写,但您的elif较低,请尝试此操作
elif answer == "H":
琐事的价值是什么?你能给我们提供输入和输出的例子吗?我试过你的代码。即使提供了正确的答案,它也会失败。不客气。您可能还希望将.upper应用于if answer==t[answeris]:,以防数据是小写的。Ok。非常感谢你!