Ошибка типа опроса с несколькими вариантами ответа: Question () не принимает аргументов - PullRequest
0 голосов
/ 13 июля 2020

Привет, я новичок в python Я все время получаю TypeError: Question () не принимает аргументов

Traceback (последний вызов последним): File "/ Users / adriankelsey / PycharmProjects / LearningPython / Создание Тест с множественным выбором / app.py ", строка 10, в вопросе (question_prompts [0]," a "), TypeError: Question () не принимает аргументов

Это Question.py

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)




    

Ответы [ 2 ]

1 голос
/ 13 июля 2020

это def __init__(self, prompt, answer)

и не

def __int__(self, prompt, answer)

0 голосов
/ 13 июля 2020

У вас есть опечатка, используйте __init__ вместо __int__. Поскольку метод __init__ не определен, это похоже на то, что ваш класс Question не принимает аргументов.

...