Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Having issues getting a multiple choice test program to work
I have been working on a program that I saw on a tutorial that creates Multiple choice test.

I created a class named Question.
Code for Question:
class Question:
    def _init_(self, prompt, answer):
        self.prompt = prompt
        self.answer = answer
The rest of my code is another file
Rest of Code:

from Question import Question
question_prompts = [
    "What kind of vessel is the Japanese Soryu Class?\n(a) Submarine\n(b) Frigate\n(c) Destroyer\n(d) Cruiser\n\n",
    "What is the primary anti-ship weapon of the US Navy?\n(a) SM2\n(b) SM6\n(c) Sea_Sparrow\n(d) Harpoon\n\n",
    "Name of the new destroyer class in the Chinese PLA Navy?\n(a) Type_45\n(b) Type_52C\n(c) Type_55\n(d) Type_23\n\n"

questions = (
    Question(question_prompts[0], "a"),
    Question(question_prompts[1], "d"),
    Question(question_prompts[2], "c"),

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(question)) + "correct ")

When I run the code the following error is created
Traceback (most recent call last): File "C:/Users/johne/PycharmProjects/untitled/Multiple choice", line 9, in <module> Question(question_prompts[0], "a"), TypeError: Question() takes no arguments
I am unsure of what the issue is with the arguments. Any help would be greatly appreciated
snippsat wrote Sep-01-2018, 06:55 PM:
Added code tag in your post,look at BBCode on how to use.
The problem is in your Question() class init method. It should have two trailing underscores on each side, not one:
# your init
def _init_(self, prompt, answer):

# correct init
def __init__(self, prompt, answer):
And next time when you post on the forums, please use Python code tags and error tags. Help is available here.
Hey guys thanks for the suggestions! You helped me fix my code. I will definitely read up on this stuff.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Proxy Issues with REQUESTS_HTML andrewnzinuk 0 88 Jun-24-2019, 05:38 AM
Last Post: andrewnzinuk
  Having issues with lives GalaxyCoyote 1 112 May-28-2019, 03:49 PM
Last Post: SheeppOSU
  Issues parsing the response from a request garnold 3 239 May-14-2019, 12:39 PM
Last Post: snippsat
  split and test tweet data Jmekubo 1 124 May-08-2019, 10:48 AM
Last Post: michalmonday
  resolving issues with path aster 5 402 Apr-01-2019, 09:54 AM
Last Post: snippsat
  Test Case Assertion Error moga2003 10 527 Mar-18-2019, 01:06 AM
Last Post: moga2003
  test pattern and add result in a table sam1975 1 190 Mar-05-2019, 02:41 PM
Last Post: sam1975
  new python package test ramkrishna 0 158 Feb-25-2019, 12:18 PM
Last Post: ramkrishna
  New to MySQL, can't work out why code doesn't work kintarowonders 6 334 Feb-18-2019, 05:23 PM
Last Post: kintarowonders
  Sorting algorithm issues Clunk_Head 2 268 Feb-17-2019, 03:58 AM
Last Post: Clunk_Head

Forum Jump:

Users browsing this thread: 1 Guest(s)