Continued exec

This commit is contained in:
Ezekiel 2021-05-28 16:01:01 +02:00
parent b2de0e105a
commit 4e18ce6911
1 changed files with 46 additions and 7 deletions

View File

@ -9,18 +9,57 @@ from collections import Counter
from rich.console import Console
from rich.markdown import Markdown
def _create_dictionnary():
# Open the CSV file and create a dictionary with all the questions
def _create_dictionary():
with open(path) as file:
reader = csv.DictReader(file)
data = list(reader)
return data
question = random.choice(data)
return question
# Count the number of questions and generate a list of IDs
def _count_questions(dictionary):
questions_id = [0]
questions_counter = 0
for questions in dictionary:
questions_counter += 1
questions_id.append(questions_counter)
questions_id.pop()
return questions_id
def _get_question(dictionary, questions_id):
questions_numbers = questions_id
print(questions_numbers)
def _print_question(question_asked):
os.system("clear")
c = Console()
actual_question = "# {}".format(question_asked["QUESTION"])
actual_question = Markdown(actual_question)
c.print(actual_question)
answers = []
for i in question_asked.keys():
if i.isnumeric():
answers.append(question_asked[i])
answer = ""
for i in answers:
answer += "1. {} \n".format(i)
answer = Markdown(answer)
c.print(answer)
def _test_question(question_asked)
if __name__ == "__main__":
path = "./data/list_book1.csv"
_create_dictionnary()
print(get_random_question())
dictionary = _create_dictionary()
questions_id = _count_questions(dictionary)
random.shuffle(dictionary)
for question in dictionary:
_print_question(question)
result = _test_question(question)
print()
#_get_question(dictionary, questions_id)