Permalink
Browse files

Merge pull request #17 from sykesda/Andrew

Andrew
  • Loading branch information...
2 parents 2a1a76a + 87f8157 commit 72e2d94b7b041c7e5da025cbfc49d5c0b9791722 @strasburgerad strasburgerad committed Sep 24, 2012
Showing with 39 additions and 12 deletions.
  1. +2 −1 QuizMain.py
  2. +18 −0 questionBank.py
  3. +17 −6 quiz.py
  4. +2 −5 userInterface.py
View
@@ -5,10 +5,11 @@
# Main file to test and run Quiz
import quiz
+import userInterface
def main():
lessonNumber = int(input('Which lesson would you like to work in? '))
- Q = Quiz(lessonNumber)
+ Q = quiz.Quiz(lessonNumber)
main()
View
@@ -27,11 +27,29 @@ def __init__(self, lesson):
for row in rows:
self.questionsList.append(row[0])
+ cur.close()
+
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()'''
+ if len(self.questionsList) == 0:
+ con = lite.connect('QuizDatabase.db') #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 QuestionIndex FROM QuestionBank WHERE LessonNumber= ? ORDER BY RANDOM()", (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])
+
+ cur.close()
+
#Grabs the first question in the list
#and removes it from said list
questionInfo = self.questionsList[0]
View
23 quiz.py
@@ -11,22 +11,33 @@ class Quiz:
def __init__(self,lesson,inaRow=5):
# Quiz object will be called a lesson parameter
# create instances of userInterface and questionBank
- self._userInterface = userInterface.UserInterface()
- self._lesson = questionBank.questionBank(lesson)
+ self._questionBank = questionBank.questionBank(lesson)
+ self._userInterface = userInterface.UserInterface(self._questionBank.getQuestion())
+
+ #initializes the first question data
+ self._userInterface.welcome()
+ self._userInterface.displayQuestion()
+ self._userInterface.prompt()
+ if(self._userInterface.getResponse()):
+ score = 1
+ else:
+ score = 0
# Pose question until 5 in a row are answered correctly
- score = 0
while score < inaRow:
# get question from question bank
- question = self._lesson.getQuestion()
+ question = self._questionBank.getQuestion()
# call on UI to display the question
# UI should return true if the question was answered correctly
# add 1 to score if the answer was correct
- if self._userInterface.display(question):
+ self._userInterface.updateQuestion(question)
+ self._userInterface.displayQuestion()
+ self._userInterface.prompt()
+ if(self._userInterface.getResponse()):
score += 1
else:
score = 0
- self._userInterface.endofQuiz()
+ self._userInterface.endOfQuiz()
View
@@ -83,14 +83,11 @@ def prompt(self):
answer = answer.lower()
answer = answer.strip()
# Get the index position of the letter for the final answer.
- self._userAnswer = self._alphabet.index(answer)
+ self._userAnswer = self._questionObj.getChoices()[self._alphabet.index(answer)]
def getResponse(self):
"""Returns whether the user entered the correct answer or not.
Returns True if the answer was correct, and returns False if
the answer was incorrect."""
- if self._userAnswer == self._questionObj.getAnswer():
- return True
- else:
- return False
+ return self._questionObj.IsCorrect(self._userAnswer)

0 comments on commit 72e2d94

Please sign in to comment.