cmon
This commit is contained in:
1 parent
b50145a7b1
commit
8b5f8c963f
4 files changed
+91
-23
No files matched your search
@@ -1 +1,2 @@
|
|||||||
quiz/__pycache__
|
quiz/__pycache__
|
||||||
|
quiz/quiz copy.py
|
||||||
+29
-18
@@ -6,22 +6,22 @@ import random
|
|||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
|
|
||||||
def load_database():
|
def load_database():
|
||||||
file = os.path.join(os.path.expanduser("~"), "Austausch", "fragen1.csv")
|
file = os.path.join(os.path.expanduser("~"), "Robotik-Ablage", "fragen2.csv")
|
||||||
|
|
||||||
#with open(file, newline="", encoding="utf-8") as csvfile: #
|
#with open(file, newline="", encoding="utf-8") as csvfile: #
|
||||||
with open(file, newline="", encoding="cp1252") as csvfile: # Code wird als Excel Windows-1252 Input CSV gelesen
|
with open(file, newline="", encoding="cp1252") as csvfile: # Code wird als Excel Windows-1252 Input CSV gelesen
|
||||||
database = csv.reader(csvfile, delimiter=";") # Validating the "csvfile" into "database" with the delimiter "," (Comma Seperated Values)
|
database = csv.reader(csvfile, delimiter=";")
|
||||||
|
|
||||||
q_a = [] # Empty list for all questions and answers
|
q_a = [] # Empty list for all questions and answers
|
||||||
|
|
||||||
for row in database: # alle Zeilen in der Datenbank durchlaufen
|
for row in database: # alle Zeilen in der Datenbank durchlaufen
|
||||||
index = int(row[0]) # Laufende Nummer
|
index = int(row[0]) # Laufende Nummer
|
||||||
question = str(row[1]) # Frage (ist der erste Teil)
|
question = str(row[1]) # Frage (ist der erste Teil)
|
||||||
answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank)
|
answer = str(row[2]) # Antwort (3. Spalte in der CSV Datenbank)
|
||||||
q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen
|
q_a.append({"index": index,"question": question, "answer": answer}) # Eine Liste bauen
|
||||||
|
|
||||||
return q_a
|
return q_a
|
||||||
|
|
||||||
|
def FahreMotor():
|
||||||
|
return True
|
||||||
|
|
||||||
fragen_liste = load_database()
|
fragen_liste = load_database()
|
||||||
random.shuffle(fragen_liste)
|
random.shuffle(fragen_liste)
|
||||||
|
|
||||||
@@ -29,23 +29,29 @@ current_index = 0
|
|||||||
correct_sum = 0
|
correct_sum = 0
|
||||||
last_correct = None
|
last_correct = None
|
||||||
max_correct_sum = 5
|
max_correct_sum = 5
|
||||||
|
|
||||||
debugtxt=""
|
debugtxt=""
|
||||||
|
alerttxt=""
|
||||||
|
successtxt=""
|
||||||
|
won=False
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
|
|
||||||
def quiz():
|
def quiz():
|
||||||
|
|
||||||
return render_template('quiz.html', frage=fragen_liste[current_index],
|
return render_template('quiz.html', frage=fragen_liste[current_index],
|
||||||
last_correct=last_correct,debugtxt=debugtxt, correct_sum=correct_sum,
|
last_correct=last_correct,debugtxt=debugtxt, correct_sum=correct_sum,
|
||||||
max_correct_sum = max_correct_sum)
|
max_correct_sum = max_correct_sum,
|
||||||
|
alerttxt=alerttxt, successtxt=successtxt,
|
||||||
|
won=won)
|
||||||
|
|
||||||
@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, alerttxt, successtxt
|
||||||
global correct_sum
|
global correct_sum
|
||||||
|
global won
|
||||||
|
|
||||||
|
won=False
|
||||||
|
|
||||||
# Ü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')
|
||||||
@@ -54,15 +60,19 @@ def submit_quiz():
|
|||||||
if user_answer == correct_answer:
|
if user_answer == correct_answer:
|
||||||
last_correct = True
|
last_correct = True
|
||||||
correct_sum += 1
|
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
|
||||||
|
successtxt = correct_answer + " ist richtig! passt zu deiner Angabe: " + user_answer
|
||||||
|
alerttxt = ""
|
||||||
elif user_answer == "42":
|
elif user_answer == "42":
|
||||||
correct_sum += 1
|
# EASTEREGG!!! #
|
||||||
debugtxt = "Korrekt! Die Antwort auf alle Fragen ist 42."
|
last_correct = True
|
||||||
|
correct_sum = 5
|
||||||
|
successtxt = "Korrekt! Die Antwort auf alle Fragen ist 42."
|
||||||
|
alerttxt = ""
|
||||||
else:
|
else:
|
||||||
last_correct = False
|
last_correct = False
|
||||||
# debugtxt += "<!-- user_answer = " + user_answer + " -->\n"
|
alerttxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer
|
||||||
# debugtxt += "<!-- correct_anwer = " + correct_answer + " -->\n"
|
successtxt = ""
|
||||||
debugtxt = "falsch: Richtig wäre " +correct_answer + " / und nicht: " + user_answer
|
|
||||||
correct_sum = 0
|
correct_sum = 0
|
||||||
|
|
||||||
current_index += 1
|
current_index += 1
|
||||||
@@ -77,9 +87,10 @@ def submit_quiz():
|
|||||||
fragen_liste = load_database()
|
fragen_liste = load_database()
|
||||||
random.shuffle(fragen_liste)
|
random.shuffle(fragen_liste)
|
||||||
current_index=0
|
current_index=0
|
||||||
debugtxt += "\nGewonnen! - Gut gemacht!"
|
successtxt += "<br /> <br /> <br /> Gewonnen! - Gut gemacht! <br /> Guten Appetit!"
|
||||||
print ("gewonnen! - Fahre 10 Sek!")
|
# print ("gewonnen! - Fahre 10 Sek!")
|
||||||
|
FahreMotor
|
||||||
correct_sum =0
|
correct_sum =0
|
||||||
|
won = True
|
||||||
|
|
||||||
# Leiten Sie den Benutzer zur nächsten Frage weiter
|
|
||||||
return redirect('/')
|
return redirect('/')
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -73,18 +73,26 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
button {
|
button {
|
||||||
background-color: rgb(106, 90, 205);
|
background-color: rgb(102, 51, 153);
|
||||||
color: rgb(255, 255, 255);
|
/* Dunkel-lila Hintergrund */
|
||||||
|
color: white;
|
||||||
|
/* Weiße Schriftfarbe */
|
||||||
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, box-shadow 0.3s ease-in-out;
|
||||||
|
box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
|
||||||
|
/* Leicht erhabener Effekt */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Aktualisierte Stilregel für den Button im Hover-Zustand */
|
||||||
button:hover {
|
button:hover {
|
||||||
background-color: rgb(72, 61, 139);
|
background-color: rgb(72, 61, 139);
|
||||||
|
/* Dunkleres Lila im Hover-Zustand */
|
||||||
|
box-shadow: 0px 6px 8px rgba(0, 0, 0, 0.2);
|
||||||
|
/* Stärkerer erhabener Effekt im Hover-Zustand */
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
@@ -103,6 +111,36 @@
|
|||||||
color: rgb(106, 90, 205);
|
color: rgb(106, 90, 205);
|
||||||
text-decoration: underline;
|
text-decoration: underline;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.alert-message {
|
||||||
|
padding: 10px;
|
||||||
|
border-radius: 5px;
|
||||||
|
font-weight: bold;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-success {
|
||||||
|
background-color: lightgreen;
|
||||||
|
color: green;
|
||||||
|
}
|
||||||
|
|
||||||
|
.alert-danger {
|
||||||
|
background-color: lightcoral;
|
||||||
|
color: red;
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container {
|
||||||
|
max-height: 50pt;
|
||||||
|
overflow: hidden;
|
||||||
|
text-align: center;
|
||||||
|
/* Zentriert das Bild horizontal */
|
||||||
|
}
|
||||||
|
|
||||||
|
.image-container img {
|
||||||
|
max-height: 50pt;
|
||||||
|
/* max-width: 100%; */
|
||||||
|
/* height: auto; */
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
@@ -110,13 +148,31 @@
|
|||||||
|
|
||||||
<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 autofocus>
|
||||||
<input type="submit" value="Quiz abschicken">
|
<button type="submit">Antwort abschicken</button>
|
||||||
<p class="q-amount">{{correct_sum}} von {{max_correct_sum}} nacheinander korrekt.</p>
|
<p class="q-amount">{{correct_sum}} von {{max_correct_sum}} nacheinander korrekt.</p>
|
||||||
<br />
|
<br />
|
||||||
{% if debugtxt %}
|
{% if debugtxt %}
|
||||||
<p class="debug">{{debugtxt}}</p>
|
<p class="debug">{{debugtxt}}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if alerttxt %}
|
||||||
|
<div id="message" class="alert-message alert-danger">
|
||||||
|
{{alerttxt}}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if successtxt %}
|
||||||
|
<div id="message" class="alert-message alert-success">
|
||||||
|
{{successtxt | safe}}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
{% if won %}
|
||||||
|
<br />
|
||||||
|
<br />
|
||||||
|
<div class="image-container">
|
||||||
|
<img src="{{ url_for('static', filename='pics/cake.jpg') }}" alt="Suessigkeit">
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|||||||
Reference in new issue
Block a user