Added explanations

This commit is contained in:
Ezekiel 2021-06-10 16:44:08 +02:00
parent d37c96daea
commit 0b08a68281
1 changed files with 23 additions and 52 deletions

View File

@ -36,64 +36,34 @@ def _print_question(question_asked):
c.print(answer) c.print(answer)
def _has_multiple_answer(question_asked): def _print_explication(question):
""" c = Console()
:param question_asked: actual_question = "# {}".format(question["EXPLICATION"])
:return Boolean: actual_question = Markdown(actual_question)
""" c.print(actual_question)
answers = str(question_asked["ANSWER"]).split()
try:
if answers[1]:
return True
except:
return False
def _one_digit_answer(question_asked):
"""
:param question_asked:
:return Boolean:
"""
result = input("What's your answer? ")
if result == question_asked["ANSWER"]:
return True
else:
return False
def _multiple_digit_answer(question_asked):
"""
:param question_asked:
:return Boolean:
"""
answers = input("What's your answer? ").split(" ")
right_answers = str(question_asked["ANSWER"]).split(" ")
if len(answers) == 0:
return False
for answer in answers:
try:
test = right_answers.index(answer)
right_answers.pop(test)
except:
return False
if len(right_answers) == 0:
return True
else:
return False
def _test_question(question_asked): def _test_question(question_asked):
""" """
:param question_asked: :param question_asked:
:return Boolean: :return Boolean:
""" """
if _has_multiple_answer(question_asked): answers = input("What is your answer? ").split()
return _multiple_digit_answer(question_asked) right_answers = str(question_asked["ANSWER"]).split()
if len(answers) == 0:
return False, question_asked["ANSWER"]
for answer in answers:
try:
test = right_answers.index(answer)
right_answers.pop(test)
except ValueError or IndexError:
return False, question_asked["ANSWER"]
if len(right_answers) == 0:
return True, question_asked["ANSWER"]
else: else:
return _one_digit_answer(question_asked) return False, question_asked["ANSWER"]
def _print_success(result): def _print_success(result, answers):
""" """
:param result: :param result:
""" """
@ -101,7 +71,7 @@ def _print_success(result):
if result: if result:
msg = "## Good job!" msg = "## Good job!"
else: else:
msg = "## that's not the right answer..." msg = "## that's not the right answer... The answer(s) was(were) ({})".format(answers)
md = Markdown(msg) md = Markdown(msg)
c.print(md) c.print(md)
@ -123,7 +93,8 @@ if __name__ == "__main__":
random.shuffle(dictionary) random.shuffle(dictionary)
for question in dictionary: for question in dictionary:
_print_question(question) _print_question(question)
result = _test_question(question) result, answers = _test_question(question)
counter.append(result) counter.append(result)
_print_success(result) _print_explication(question)
_print_success(result, answers)
print_stats(counter) print_stats(counter)