Permalink
Browse files

Greg's Question Bank class

  • Loading branch information...
1 parent 1f81dd7 commit 446aa5cfeac5623438f45e97dc88795b21ca7cde @strasburgerad strasburgerad committed Sep 23, 2012
Showing with 60 additions and 0 deletions.
  1. +60 −0 questionBank.py
View
@@ -0,0 +1,60 @@
+#Greg Valainis COSC 410
+#Question Bank
+import sqlite3 as lite
+import random
+
+class questionBank(object):
+
+ def __init__(self, lesson):
+ '''Initializes the questionBank object
+ pre: User gives a lesson number and the table
+ post: A list of all the questions is created'''
+
+ self.lesson = lesson
+
+ #Connect to the DB and create a cursor
+ con = lite.connect('main') #insert the database name here
+ cur = con.cursor()
+
+ #Select all the question Id's from the question bank
+ #given the appropriate lesson
+ cur.execute("SELECT questionIndx FROM QuizDatabase.db WHERE lesson={}".format(self.lesson))
+ rows = cur.fetchall()
+
+ #Take all of the question Id's and put them in a list
+ self.questionsList = []
+ for row in rows:
+ self.questionsList.append(row[0])
+
+
+ #The list of questions needs to be randomized
+ #Can be done via sqlite but not sure how
+ random.shuffle(self.questionsList)
+
+ def getQuestion(self):
+ '''Grabs a random question from the database to be used next
+ pre: questionsList cannot be empty
+ post: creates an instance of Question()'''
+
+ #Grabs the first question in the list
+ #and removes it from said list
+ questionInfo = self.questionsList[0]
+ self.questionsList.pop(0)
+
+ #Input code here for making sure the user does not receive
+ #A question he/she has recently gotten right
+ ##########################################
+
+
+
+ ##########################################
+
+
+ #Returns an instance of question with the appropriate information
+ return Question(questionInfo)
+
+
+
+
+
+

0 comments on commit 446aa5c

Please sign in to comment.