Pruefungskatalog/question_answer_output.py

25 lines
636 B
Python
Raw Normal View History

2022-03-21 15:46:51 +01:00
import json
from random import randrange
2022-03-21 22:19:07 +01:00
# Einlesen vom Json File
2022-03-21 15:46:51 +01:00
def read_json(filename):
2022-03-21 22:19:07 +01:00
with open(filename,encoding='utf-8') as filename:
2022-03-21 15:46:51 +01:00
data = json.load(filename)
return data
2022-03-21 22:19:07 +01:00
2022-03-21 15:46:51 +01:00
# Zufällige Frage erstellen
def random_question(filename):
2022-03-22 08:33:31 +01:00
min_ = 0
max_ = len(read_json(filename))
random_number = randrange(min_,max_)
2022-03-21 15:46:51 +01:00
questions = read_json(filename)
2022-03-21 22:19:07 +01:00
question = f'Frage #{random_number}: ' + questions[random_number][str(random_number)]['question']
2022-03-21 15:46:51 +01:00
answer = questions[random_number][str(random_number)]['answer']
return question, answer
#print(random_question(config.json_file)[0])