Code: Alles auswählen
HEADING_ANGLE = {
"Gegenanflug": -180,
"Rechter Gegenanflug": -180,
"Queranflug": 90,
"Rechter Queranflug": -90,
}
def calculate_current_heading(flight_position, heading):
return (heading + HEADING_ANGLE[flight_position]) % 360
Code: Alles auswählen
def format_heading(heading):
return f"{heading:03d}"
Code: Alles auswählen
def question_ids():
return [number for number, _ in enumerate(QUESTIONS, 1)
`get_answers_in_random_order` ist unnötigerweise auf 4 Antworten festgelegt. Mit shuffle wäre das klarer:
Code: Alles auswählen
def get_answers_in_random_order(question_id):
answers = list(QUESTIONS[question_id - 1]["answers"])
random.shuffle(answers)
return answers
Code: Alles auswählen
def check_right_answer(question_id, answer):
return answer == QUESTIONS[question_id - 1]["answers"][0]
Code: Alles auswählen
def render_question(question_id, rating=None, answers=None):
if answers is None:
answers = get_answers_in_random_order(question_id)
return render_template(
"question.html",
question=get_question(question_id),
id=question_id,
answers=answers,
answers_json=dumps(answers),
rating=rating,
)
@app.route("/question", methods=["GET", "POST"])
def chose_question():
question_id = int(request.form["id"])
return render_question(question_id)
@app.route("/answer", methods=["GET", "POST"])
def check_answer():
question_id = int(request.form["id"])
answer = request.form["answer"]
answers = loads(request.form["answers_json"])
rating = (
f"Richtig!\n{answer}" if get_right_answer(question_id, answer) else "Falsch!"
)
return render_question(question_id, rating, answers)
@app.route("/next", methods=["GET", "POST"])
def next_question():
question_id = int(request.form["id"]) + 1
try:
_ = get_question(question_id)
except IndexError:
return render_template("finish.html")
return render_question(question_id)
@app.route("/back", methods=["GET", "POST"])
def previous_question():
question_id = int(request.form["id"]) - 1
if question_id < 1:
return index()
return render_question(question_id)