【发布时间】:2018-05-07 01:39:09
【问题描述】:
因此,我正在尝试进行一种测验,您可以从中选择不同的类别。它工作得很好,但我不能让分数功能正常工作。如果我在三个正确答案后打印(分数)(分数应该是 3),它仍然显示 0。 如果我将返回分数放在分数 += 1 之后,它会在一个正确答案后自动停止,但我希望能够给出 3 个正确答案。
下面是部分代码
def quizquestion(score,question_category):
for question_number,question in enumerate(question_category):
print ("Question",question_number+1)
time.sleep(1)
slow_type (question)
for options in question_category[question][:-1]:
slow_type (options)
user_choice = input("make your choice: ")
if user_choice == question_category[question][-1]:
replay = good[random.randint(0,7)]
slow_type (replay)
score += 1
else:
replay = wrong[random.randint(0,7)]
slow_type (replay)
slow_type ("The correct answer should have been")
print(question_category[question][-1])
time.sleep(1)
slow_type("okay you finished this category, lets see what your score is in this category")
slow_type("You have"), print(score), slow_type("correct answer(s)")
return score
其中一个类别:
questions_random = {
"How tall is the Eiffel Tower?":['a. 350m', 'b. 342m', 'c. 324m', 'd. 1000ft','a'],
"How loud is a sonic boom?":['a. 160dB', 'b. 175dB', 'c. 157dB', 'd. 213dB', 'd'],
"What is the highest mountain in the world?":['a. Mont Blanc', 'b. K2', 'c. Mount Everest', 'd. Mount Kilomonjaro', 'c']
}
如果您需要更多代码来帮助我,请告诉我
【问题讨论】:
-
请发布一个 mcve 删除所有不相关的代码并包括函数 id 的调用方式。
-
我无法重现该错误。用
print替换slow_type并删除replay的东西后,代码对我来说可以正常工作。最好发布一个完整的例子。另外,score函数是什么意思?没有使用此名称的函数或函数调用。
标签: python python-3.x function spyder enumerate