This commit is contained in:
br committed 2023-12-18 21:42:25 +01:00
1 parent ccbf300047
commit b50145a7b1
3 files changed
+129 -105

No files matched your search

+6 -1
View File
@@ -3,4 +3,9 @@ FLASK_APP=quiz.py
FLASK_DEBUG=True FLASK_DEBUG=True
FLASK_RUN_HOST=0.0.0.0 FLASK_RUN_HOST=0.0.0.0
#FLASK_RUN_HOST=127.0.0.1 #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
+20 -1
View File
@@ -26,7 +26,9 @@ fragen_liste = load_database()
random.shuffle(fragen_liste) random.shuffle(fragen_liste)
current_index = 0 current_index = 0
correct_sum = 0
last_correct = None last_correct = None
max_correct_sum = 5
debugtxt="" debugtxt=""
@@ -34,13 +36,16 @@ debugtxt=""
def quiz(): 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']) @app.route('/submit_quiz', methods=['POST'])
def submit_quiz(): def submit_quiz():
global current_index global current_index
global fragen_liste global fragen_liste
global debugtxt global debugtxt
global correct_sum
# Überprüfen Sie die Antwort und aktualisieren Sie current_index # Überprüfen Sie die Antwort und aktualisieren Sie current_index
user_answer = request.form.get('answer') user_answer = request.form.get('answer')
@@ -48,12 +53,18 @@ def submit_quiz():
if user_answer == correct_answer: if user_answer == correct_answer:
last_correct = True last_correct = True
correct_sum += 1
debugtxt = correct_answer + " ist richtig! passt zu deiner Angabe: " + user_answer 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: else:
last_correct = False last_correct = False
# debugtxt += "<!-- user_answer = " + user_answer + " -->\n" # debugtxt += "<!-- user_answer = " + user_answer + " -->\n"
# debugtxt += "<!-- correct_anwer = " + correct_answer + " -->\n" # debugtxt += "<!-- correct_anwer = " + correct_answer + " -->\n"
debugtxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer debugtxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer
correct_sum = 0
current_index += 1 current_index += 1
# Überprüfen, ob wir alle Fragen beantwortet haben # Überprüfen, ob wir alle Fragen beantwortet haben
@@ -62,5 +73,13 @@ def submit_quiz():
random.shuffle(fragen_liste) random.shuffle(fragen_liste)
current_index=0 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 # Leiten Sie den Benutzer zur nächsten Frage weiter
return redirect('/') return redirect('/')
+103 -103
View File
@@ -1,124 +1,124 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- <link rel="stylesheet" href="../.data/style/forms.css"> <title>Hausaufgaben-Robo</title>
<link rel="stylesheet" href="../.data/style/main.css"> --> <style>
<title>Login</title> body {
<style> font-family: 'Arial', sans-serif;
body { margin: 0;
font-family: 'Arial', sans-serif; padding: 0;
margin: 0; display: flex;
padding: 0; justify-content: center;
display: flex; align-items: center;
justify-content: center; height: 100dvh;
align-items: center; }
height: 100dvh;
}
body { body {
background: linear-gradient(315deg, rgb(134, 65, 163) 0%, rgb(196, 99, 238) 100%); background: linear-gradient(315deg, rgb(134, 65, 163) 0%, rgb(196, 99, 238) 100%);
} }
form { form {
background-color: rgb(255, 255, 255); background-color: rgb(255, 255, 255);
padding: 20px; padding: 20px;
border-radius: 8px; border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
width: 300px; width: 300px;
box-sizing: border-box; box-sizing: border-box;
transition: box-shadow 0.3s ease-in-out; transition: box-shadow 0.3s ease-in-out;
} }
form:hover { form:hover {
box-shadow: 0 0 15px rgba(0, 0, 0, 0.2); box-shadow: 0 0 15px rgba(0, 0, 0, 0.2);
} }
label { label {
display: block; display: block;
margin-bottom: 8px; margin-bottom: 8px;
color: rgb(102, 51, 153); color: rgb(102, 51, 153);
} }
input { input {
width: 100%; width: 100%;
padding: 8px; padding: 8px;
margin-bottom: 16px; margin-bottom: 16px;
background-color: transparent !important; background-color: transparent !important;
box-sizing: border-box; box-sizing: border-box;
border: none; border: none;
border-bottom: 1px solid rgb(142, 68, 173, 0.25); border-bottom: 1px solid rgb(142, 68, 173, 0.25);
outline: none; outline: none;
transition: border-bottom 0.3s ease-in-out; transition: border-bottom 0.3s ease-in-out;
position: relative; position: relative;
} }
input:focus, input:focus,
input:hover { input:hover {
border-bottom: 1px solid rgb(142, 68, 173, 1); border-bottom: 1px solid rgb(142, 68, 173, 1);
} }
input+label { input+label {
position: absolute; position: absolute;
top: 8px; top: 8px;
left: 8px; left: 8px;
color: #8E44AD; color: #8E44AD;
transition: top 0.3s ease-in-out, font-size 0.3s ease-in-out; transition: top 0.3s ease-in-out, font-size 0.3s ease-in-out;
} }
input:focus+label, input:focus+label,
input:not(:placeholder-shown)+label { input:not(:placeholder-shown)+label {
top: -14px; top: -14px;
font-size: 12px; font-size: 12px;
} }
button { button {
background-color: rgb(106, 90, 205); background-color: rgb(106, 90, 205);
color: rgb(255, 255, 255); color: rgb(255, 255, 255);
padding: 10px; padding: 10px;
border: none; border: none;
border-radius: 4px; border-radius: 4px;
cursor: pointer; cursor: pointer;
width: 100%; width: 100%;
transition: background-color 0.3s ease-in-out; transition: background-color 0.3s ease-in-out;
} }
button:hover { button:hover {
background-color: rgb(72, 61, 139); background-color: rgb(72, 61, 139);
} }
p { p {
color: rgb(106, 90, 205); color: rgb(106, 90, 205);
text-align: center; text-align: center;
margin-top: 10px; margin-top: 10px;
margin-bottom: 10px; margin-bottom: 10px;
} }
p.q-amount { p.q-amount {
font-size: small; font-size: small;
color: rgb(180, 180, 180); color: rgb(180, 180, 180);
} }
a { a {
color: rgb(106, 90, 205); color: rgb(106, 90, 205);
text-decoration: underline; text-decoration: underline;
} }
</style> </style>
</head> </head>
<body> <body>
<form method="POST" action="/submit_quiz"> <form method="POST" action="/submit_quiz">
<p name="question">{{ frage.index }}. {{ frage.question }}</p> <p name="question">{{ frage.index }}. {{ frage.question }}</p>
<input type="text" name="answer" placeholder="Antwort eingeben..." required> <input type="text" name="answer" placeholder="Antwort eingeben..." required>
<input type="submit" value="Quiz abschicken"> <input type="submit" value="Quiz abschicken">
<p class="q-amount">N/A von N/A beantwortet!</p> <p class="q-amount">{{correct_sum}} von {{max_correct_sum}} nacheinander korrekt.</p>
<br /> <br />
<p class="debug">{{debugtxt}}</p> {% if debugtxt %}
</form> <p class="debug">{{debugtxt}}</p>
{% endif %}
</form>
</body> </body>
</html> </html>