-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestionClass.py
More file actions
41 lines (33 loc) · 1.2 KB
/
QuestionClass.py
File metadata and controls
41 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import inquirer
from helpers import clear
class Question():
def __init__(self, question, correct_answer, incorrect_answers):
self.question = question
self.correct_answer = correct_answer
self.incorrect_answers = incorrect_answers
def ask_question(self):
clear()
print("The question is: ")
print(self.question)
def ask_answers(self):
while True:
questions = [inquirer.Checkbox(
'answers',
message="What is/are the answer(s) ?",
choices=self.incorrect_answers + [self.correct_answer],
)]
answers = inquirer.prompt(questions)
if answers['answers'] == []:
clear()
print("Please, select at least one answer.")
print(self.question)
continue
verify = self.verify_answer(answers['answers'])
if verify:
print("Correct !")
return True
else:
print("Incorrect !")
return False
def verify_answer(self, answer):
return answer[0] == self.correct_answer