Compare commits

..

No commits in common. "90befc0953ee9074d9a73b6d9937a478b6c25503" and "d37c96daea46e70947063da0b9887a9ca5c26ac3" have entirely different histories.

2 changed files with 52 additions and 114 deletions

View File

@ -1,91 +0,0 @@
#!/usr/bin/python3
import pathlib
import csv
import random
import os
from rich.console import Console
from rich.markdown import Markdown
def loading_file(file_path):
# loading file to working with
diction_reader = csv.DictReader(open(file_path, "r"))
data = []
for e in diction_reader:
data.append(e)
return data
def choice_question(data):
choice = random.choice(data)
return choice
def show_questions(choice):
os.system("clear")
c = Console()
quest = "# {}".format(choice["QUESTION"])
quest = Markdown(quest)
c.print(quest)
def show_answers(choice):
os.system("clear")
c = Console()
answer = []
for i in choice.keys():
if i.isnumeric():
answer.append(choice[i])
answers = ""
for i in answer:
if len(i) > 0:
answers += "1. {} \n".format(i)
answers = Markdown(answers)
c.print()
c.print(answers)
def prompt_answer(choice):
reply_answ = input("What is your answer ? ")
if reply_answ in choice["ANSWER"]:
return True
else:
return False
def print_explication(choice):
c = Console()
explication = "# {}".format(choice["EXPLICATION"])
explication = Markdown(explication)
c.print(explication)
def print_success(choice):
c = Console()
if choice:
mess1 = "## Good Answer!"
else:
mess1 = "## Ho no ... ! that's not the right answer..."
mess = Markdown(mess1)
c.print(mess)
def print_stats():
pass
if __name__ == "__main__":
file_path = pathlib.Path('./data/list_book1.csv')
data = loading_file(file_path)
try:
while True:
result = choice_question(data)
show_questions(result)
show_answers(result)
result1 = prompt_answer(result)
print_success(result1)
print_explication(result)
except KeyboardInterrupt:
print("Ciao Ciao")

View File

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