You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

21 lines
730 B

from fastapi import FastAPI
import json
import random
app = FastAPI()
with open("questions.json", "r", encoding="UTF-8") as f:
content = json.load(f)
questions_with_answers = content["questions"]
remove_keys = ["author", "answer", "topic"]
questions_without_answers = [{key: value for key, value in q.items() if key not in remove_keys} for q in questions_with_answers]
@app.get("/")
def give_quiz(student: str):
quiz_questions = random.sample(questions_without_answers, len(questions_without_answers)) # questions selection would be more complicated
return {
"version": 1,
"student": student,
"attempt": 0, # TODO how to count attempts?
"questions": quiz_questions
}