我正在尝试创建测验,并且questions第二元素的数组中存在语法错误。我试图通过`for循环将每个对象附加到数组,但是我需要每个问题都有正确的答案。
Questions 类位于不同的文件中:
class Questions:
def __init__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
这是主文件:
from Questions import Questions
questionsPrompt = ["What does CPU stand for?\n(a) central procesing unit\n(b)controlled purification\n(c)computer unit",
"What is an advantage of a compiler?\n(a)slow to run each time\n(b)compiling takes a long time\n(c)easy to implement",
"The Operating System is a :\n(a)system software\n(b)application software\n(c)utility software"]
questions = [
Questions(questionsPrompt[0], "a")
Questions(questionsPrompt[1], "b")
Questions(questionsPrompt[2], "a")
]
def runQuiz(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
return score
runQuiz(questions)
开满天机
鸿蒙传说
相关分类