Apr-02-2020, 05:54 PM
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:
This is the class I create:
class Question: def __int__(self, prompt, answer): self.prompt = prompt self.answer = answerThis 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