From b50145a7b1b6ca4662a6d86f6133b9658cd18c3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Runden?= Date: Mon, 18 Dec 2023 21:42:25 +0100 Subject: [PATCH] erl. --- quiz/.env | 7 +- quiz/quiz.py | 21 +++- quiz/templates/quiz.html | 206 +++++++++++++++++++-------------------- 3 files changed, 129 insertions(+), 105 deletions(-) diff --git a/quiz/.env b/quiz/.env index 163fed7..c877def 100644 --- a/quiz/.env +++ b/quiz/.env @@ -3,4 +3,9 @@ FLASK_APP=quiz.py FLASK_DEBUG=True FLASK_RUN_HOST=0.0.0.0 #FLASK_RUN_HOST=127.0.0.1 -FLASK_RUN_PORT=5003 +FLASK_RUN_PORT=5002 + +GUNICORN_APP_MODULE=quiz:app +#GUNICORN_BIND=0.0.0.0:5003 +GUNICORN_WORKERS=4 + diff --git a/quiz/quiz.py b/quiz/quiz.py index f30273a..48a2e9e 100644 --- a/quiz/quiz.py +++ b/quiz/quiz.py @@ -26,7 +26,9 @@ fragen_liste = load_database() random.shuffle(fragen_liste) current_index = 0 +correct_sum = 0 last_correct = None +max_correct_sum = 5 debugtxt="" @@ -34,13 +36,16 @@ debugtxt="" def quiz(): - return render_template('quiz.html', frage=fragen_liste[current_index],last_correct=last_correct,debugtxt=debugtxt) + return render_template('quiz.html', frage=fragen_liste[current_index], + last_correct=last_correct,debugtxt=debugtxt, correct_sum=correct_sum, + max_correct_sum = max_correct_sum) @app.route('/submit_quiz', methods=['POST']) def submit_quiz(): global current_index global fragen_liste global debugtxt + global correct_sum # Überprüfen Sie die Antwort und aktualisieren Sie current_index user_answer = request.form.get('answer') @@ -48,12 +53,18 @@ def submit_quiz(): if user_answer == correct_answer: last_correct = True + correct_sum += 1 debugtxt = correct_answer + " ist richtig! passt zu deiner Angabe: " + user_answer + elif user_answer == "42": + correct_sum += 1 + debugtxt = "Korrekt! Die Antwort auf alle Fragen ist 42." else: last_correct = False # debugtxt += "\n" # debugtxt += "\n" debugtxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer + correct_sum = 0 + current_index += 1 # Überprüfen, ob wir alle Fragen beantwortet haben @@ -62,5 +73,13 @@ def submit_quiz(): random.shuffle(fragen_liste) current_index=0 + if correct_sum >= 5: + fragen_liste = load_database() + random.shuffle(fragen_liste) + current_index=0 + debugtxt += "\nGewonnen! - Gut gemacht!" + print ("gewonnen! - Fahre 10 Sek!") + correct_sum =0 + # Leiten Sie den Benutzer zur nächsten Frage weiter return redirect('/') diff --git a/quiz/templates/quiz.html b/quiz/templates/quiz.html index 3b1bc61..d1bc6de 100644 --- a/quiz/templates/quiz.html +++ b/quiz/templates/quiz.html @@ -1,124 +1,124 @@ - - - - - Login - - + a { + color: rgb(106, 90, 205); + text-decoration: underline; + } + + - + -
-

{{ frage.index }}. {{ frage.question }}

- - -

N/A von N/A beantwortet!

-
-

{{debugtxt}}

-
+
+

{{ frage.index }}. {{ frage.question }}

+ + +

{{correct_sum}} von {{max_correct_sum}} nacheinander korrekt.

+
+ {% if debugtxt %} +

{{debugtxt}}

+ {% endif %} +
- + \ No newline at end of file