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):
|
|
|
|
min = 0
|
|
|
|
max = len(read_json(filename))
|
|
|
|
random_number = randrange(min,max)
|
|
|
|
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])
|
|
|
|
|