Skip to content
Snippets Groups Projects
Commit 2b2b7c14 authored by thomaskmatthew's avatar thomaskmatthew
Browse files

closes app after five questions are answer

parent fdc45e19
No related branches found
No related tags found
No related merge requests found
......@@ -76,6 +76,7 @@ class QuizzerApp(App):
paused = BooleanProperty(False)
correct = BooleanProperty(False)
score = NumericProperty(0)
total = NumericProperty(0)
def build(self):
inspector.create_inspector(Window, self)
......@@ -107,13 +108,16 @@ class QuizzerApp(App):
self.reshuffle()
def answer(self, answer):
self.total += 1
question = self.questions[-1] if len(self.questions) > 0 else QuizzerApp.DEFAULT_QUESTION
self.paused = True
self.correct = answer == question[2]
if self.correct:
self.score += 1
print(f'You got it correct, number of right are: {self.score}')
print(f'You got it correct, number of right are: {self.score} out of {self.total}')
else:
print(f'total number of questions: {self.score} out of {self.total}')
Clock.schedule_once(lambda delta: self.unpause(), PAUSE_TIME)
def unpause(self):
......@@ -122,6 +126,8 @@ class QuizzerApp(App):
self.questions.pop()
if len(self.questions) == 0:
self.reshuffle()
if self.total == 5:
app.exit()
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment