Python 多项选择测验类型错误:问题()不接受参数
大家好,我是python新手,我一直在学习TypeError:Question()不带参数 回溯(最近一次呼叫最后一次): 文件“/Users/adriankelsey/PycharmProjects/LearningPython/Building a multi-selection quick/app.py”,第10行,在 问题(问题[0],“a”), TypeError:Question()不接受任何参数 这是问题Python 多项选择测验类型错误:问题()不接受参数,python,python-3.8,Python,Python 3.8,大家好,我是python新手,我一直在学习TypeError:Question()不带参数 回溯(最近一次呼叫最后一次): 文件“/Users/adriankelsey/PycharmProjects/LearningPython/Building a multi-selection quick/app.py”,第10行,在 问题(问题[0],“a”), TypeError:Question()不接受任何参数 这是问题 class Question: def __int__(self,
class Question:
def __int__(self, prompt, answer):
self.prompt = prompt
self.answer = answer
这在app.py中
from Question import Question
question_prompts = [
"What color are apples?\n(a) Red/green\n(b) Purple\n(c) Orange\n\n",
"What color are bananas?\n(a) Teal\n(b) Magenta \n(c) Yellow\n\n",
"What color are strawberries?\n(a) Yellow\n(b) Red\n(c) Blue\n\n"
]
questions = [
Question(question_prompts[0], "a"),
Question(question_prompts[1], "c"),
Question(question_prompts[2], "b"),
]
def run_test(questions):
score = 0
for question in questions:
answer = input(question.prompt)
if answer == question.answer:
score += 1
print("You got " + str(score + "/" + str(len(questions) + " correct")))
run_test(questions)
您有一个输入错误,请使用
\uuuuu init\uuuuuu
而不是\uuuu int\uuuu
。因为方法\uuuu init\uuuu
没有定义,这就像你的类问题
没有参数一样。它是def\uuuu init\uuu(self,prompt,answer)
而不是
def\uuuu int\uuuu(自我、提示、回答)