Python Forum
Question() takes no arguments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question() takes no arguments
#1
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
Reply
#2
Line 2 in your Question class has a typo in it.
Reply
#3
(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 >.<
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [split] Class takes no arguments bily071 2 633 Oct-23-2023, 03:59 PM
Last Post: deanhystad
  Error TypeError: output_type_handler() takes 2 positional arguments but 6 were given paulo79 1 1,935 Oct-17-2022, 06:29 PM
Last Post: paulo79
  Checking the number of arguments a function takes Chirumer 3 2,153 Jul-06-2021, 04:56 PM
Last Post: Chirumer
  Class Takes No Arguments horuscope42 4 4,817 Oct-26-2020, 11:10 PM
Last Post: not_username1234
  Class takes no arguments Nazartfya 2 4,565 Jun-27-2020, 12:45 PM
Last Post: Nazartfya
  Why Car() takes no arguments louis216 2 2,601 Jun-25-2020, 03:16 AM
Last Post: louis216
  random.choice() takes two positional arguments, but three were given. ShakeyPakey 5 11,660 May-31-2020, 03:13 PM
Last Post: deanhystad
  add() takes 2 positional arguments but 3 were given Man_from_India 3 5,769 Feb-10-2020, 05:08 PM
Last Post: Man_from_India
  Class takes no arguments Myang123 3 9,792 Nov-26-2019, 12:01 PM
Last Post: Davy_Jones_XIV
  This constructor takes no arguments Friend 2 5,316 Jun-26-2019, 02:54 PM
Last Post: Friend

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020