0

I'm working on a program that is able to make quizzes by exporting questions into a database. I've looked on the internet for a bit and it said that one of the easiest ways to import or export to a database in python is to use the SQLite3 plugin, so I'm trying it out.This is the first time I've used the SQLite3 plugin with python, and I keep getting a syntax error on the self.connection.commit() in:

def AddQuestion(self, Question, Answer1, Answer2, Answer3, Answer4):
    self.cursor.execute("""INSERT INTO questions
                            VALUES (?, ?, ?, ?, ?, ?)""", (None, Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer)
    self.connection.commit()

If I were to turn it into a comment by adding # before it, it would tell me that the print in this was a syntax error:

print ("Would you like to make a test? Or would you like to take a test?")

Maybe its my indentation, or am I doing something wrong?

import squlite3
class QuestionStorage(object):
    def _init_(self, path):
        self.connection = sqlite3.connect(path)
        self.cursor = self.connection.cursor ()

def Close(self):
    self.cursor.close()
    self.connection.close()

def CreateDb(self):
    query = """CREATE TABLE questions
             (id INTEGER PRIMARY KEY, Question TEXT, Answer1 TEXT, Answer2 TEXT, Answer3 TEXT, Answer4 TEXT, CorrectAnswer TEXT)"""
    self.cursor.exeute(query)
    self.connection.commit()
    #self.cursor.close()

def AddQuestion(self, Question, Answer1, Answer2, Answer3, Answer4):
    self.cursor.execute("""INSERT INTO questions
                            VALUES (?, ?, ?, ?, ?, ?)""", (None, Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer)
    self.connection.commit()

def GetQuestion(self, index = None):
    self.cursor.execute("""SELECT * FROM questions WEHRE id=?""", (index,))



print ("Would you like to make a test? Or would you like to take a test?")
testTaker = input ("To create a test, type Create. To take a test, type Take.")

if testTaker == "Create":
    testName = input ("Give your test a name.")
    testQ = int(input ("How many questions will be on this test? (Numeric value only.)"))
    testType = input ("Will this test be multiple choice? (y/n)")
    if testType == "N" or "n":
        counter = 1
        qs = QuestionStorage("questions.db")
        qs.CreateDb()
        counter = 1
        while counter >= testQ:
            Answer = []
            Question = input ("What is your question?")
            Answer[1] = input ("What is the first answer?")
            Answer[2] = input ("What is the second answer?")
            Answer[3] = input ("What is the third answer?")
            Answer[4] = input ("What is your last answer?")
            correctAnswer = input("Which answer is the correct answer? (1, 2, 3, or 4?)")
            Answer[5] = Answer[correctAnswer]

        qs.AddQuestion(Question, Answer[1] , Answer[2], Answer[3], Answer[4], Answer[5])
        counter +=1


else:

and then after the else, I'd have the code for reading the database to take a test.

If anyone can help me out with this, that would be great. Right now I'm just trying to get it to the point where I can run it in debug.

1 Answer 1

5

You forgot to close the parentheses here:

self.cursor.execute("""INSERT INTO questions
                        VALUES (?, ?, ?, ?, ?, ?)""", (None, Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer)

Put another closing ) at the end of the line.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.