Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 50 lines (36 sloc) 1.355 kb
1f81dd7c »
2012-09-21 The Question class that Katie and I wrote
1 #!/usr/bin/python3.1
2
3 __author__ = "Katie, Andrew"
4 __date__ = "09/18/12"
5 import sqlite3
6
7
8 class Question:
9 """A class used to return values of Question to userInterface.py"""
10
11 def __init__(self, questionIndx):
12 conn = sqlite3.connect('QuizDatabase.db')
13 c = conn.cursor()
14 c.execute('select QuestionText, LessonNumber from QuestionBank where QuestionIndex =?', (questionIndx,))
15 temp = c.fetchone()
16 questionText, lessonNumber = temp[0], temp[1]
17 lessonNumber = float(lessonNumber)
18 self.questionText = questionText
19 self.lessonNumber = lessonNumber
20 self.questionIndx = questionIndx
21
22 # Query to the database to get choices
23 c.execute('select AnswerText from QuestionAnswers where QuestionIndex =? ORDER BY RANDOM()', (questionIndx,))
24 temp = c.fetchall()
25 tempChoices = []
26 for choice in temp:
27 tempChoices = tempChoices + [choice[0]]
28 self.choices = tuple(tempChoices)
29
30 # Query to the database to get the correct answer
31 c.execute('select AnswerText from QuestionAnswers where QuestionIndex =? and isCorrect = 1', (questionIndx,))
32 temp = c.fetchone()
33 self.answer = temp[0]
34
35 c.close()
36
37
38 def getQuestionText(self):
39 return self.questionText
40
41 def getChoices(self):
42 return self.choices
43
44 def getAnswer(self):
45 return self.answer
46
19ab7796 »
2012-09-23 added a IsCorrect function
47 def IsCorrect(self, choiceText):
48 return (choiceText == self.answer)
49
Something went wrong with that request. Please try again.