Python Forum

Full Version: Question() takes no arguments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, I just started to learn python and tried to write a simple multiple-choice code, but it kept reporting an error. Could someone help me with that?
This is the class I create:
class Question:
    def __int__(self, prompt, answer):
        self.prompt = prompt
        self.answer = answer
This is the multiple-choice question:
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(question):
    score = 0
    for question in questions:
        answer = input(question.prompt)
        if answer == question.answer:
            score += 1
    print("You got " + str(score) + "/" + str(len(question)) + " correct")


run_test(questions)
This is the traceback:
Error:
Traceback (most recent call last): File "E:/python files/Youtube Courses.py", line 10, in <module> Question(question_prompts[0], "a"), TypeError: Question() takes no arguments Process finished with exit code 1
Line 2 in your Question class has a typo in it.
(Apr-02-2020, 05:55 PM)ndc85430 Wrote: [ -> ]Line 2 in your Question class has a typo in it.
xxxD oh my... silly problem
Thanks for help >.<