From 7eca5bfedcaa73c0ff8ab9221d1760212677dbb5 Mon Sep 17 00:00:00 2001 From: marcus Date: Mon, 21 Mar 2022 15:46:51 +0100 Subject: [PATCH] 21.03.2022 --- config.py | 2 ++ json_reader.py | 1 - main_menu.py | 10 ++++++--- question_answer_output.py | 25 +++++++++++++++++++++ questions_answers.json | 46 ++++++++++++++++++++++----------------- 5 files changed, 60 insertions(+), 24 deletions(-) delete mode 100644 json_reader.py create mode 100644 question_answer_output.py diff --git a/config.py b/config.py index ef693fe..277b18a 100644 --- a/config.py +++ b/config.py @@ -5,3 +5,5 @@ user = 'root' password = '' host = 'localhost' + +json_file = 'questions_answers.json' \ No newline at end of file diff --git a/json_reader.py b/json_reader.py deleted file mode 100644 index 7e5768c..0000000 --- a/json_reader.py +++ /dev/null @@ -1 +0,0 @@ -# TODO: einlesen der berreits vorhanden Daten im JSON File \ No newline at end of file diff --git a/main_menu.py b/main_menu.py index 0833bd3..f958a7a 100644 --- a/main_menu.py +++ b/main_menu.py @@ -1,5 +1,6 @@ +import config import database_menu - +import question_answer_output # Main Menu @@ -17,7 +18,10 @@ def main_menu(): database_menu.menu() break case 1: - # TODO Starte Zufallsfragenausgabe - return + while True: + question_answer_output.random_question(config.json_file) + number = int(input('Zurück zum Hauptmenü\n 1: Ja \n 2: Nein\n')) + if number == 1: + break case 2: break diff --git a/question_answer_output.py b/question_answer_output.py new file mode 100644 index 0000000..70f47d0 --- /dev/null +++ b/question_answer_output.py @@ -0,0 +1,25 @@ +# TODO: einlesen der berreits vorhanden Daten im JSON File + +import json +from random import randrange + + +# Einlesen Json File +def read_json(filename): + with open(filename) as filename: + data = json.load(filename) + return data + +# Zufällige Frage erstellen +def random_question(filename): + min = 0 + max = len(read_json(filename)) + random_number = randrange(min,max) + questions = read_json(filename) + question = f'Frage Nr:', random_number, questions[random_number][str(random_number)]['question'] + answer = questions[random_number][str(random_number)]['answer'] + return question, answer + + +#print(random_question(config.json_file)[0]) + diff --git a/questions_answers.json b/questions_answers.json index ffa18a6..b5483fe 100644 --- a/questions_answers.json +++ b/questions_answers.json @@ -1,60 +1,66 @@ [ { - "#1": { + "0": { + "question": "Was versteht man unter dem Begriff Cross-Selling?", + "answer": "Eine Verkaufsstrategie, bei der zu einem Produkt, zusätzliche ( inhalte, produkte, services etc...) angeboten werden, um einen höheren Umsatz und die Kundenanbindung zu erhöhen" + } + }, + { + "1": { + "question": "", + "answer": "" + } + }, + { + "2": { "question": " ", "answer": " " } }, { - "#2": { + "3": { + "question": "", + "answer": "" + } + }, + { + "4": { "question": " ", "answer": " " } }, { - "#3": { + "5": { "question": " ", "answer": " " } }, { - "#4": { + "6": { "question": " ", "answer": " " } }, { - "#5": { + "7": { "question": " ", "answer": " " } }, { - "#6": { + "8": { "question": " ", "answer": " " } }, { - "#7": { + "9": { "question": " ", "answer": " " } }, { - "#8": { - "question": " ", - "answer": " " - } - }, - { - "#9": { - "question": " ", - "answer": " " - } - }, - { - "#10": { + "10": { "question": " ", "answer": " " }