Fausto Busuito
commited on
Commit
•
5b846f1
1
Parent(s):
5b15795
Application changes
Browse files- app.py +16 -6
- templates/quiz.html +15 -6
app.py
CHANGED
@@ -44,12 +44,22 @@ def quiz():
|
|
44 |
if request.method == 'POST':
|
45 |
action = request.form.get('action')
|
46 |
if action == 'next':
|
|
|
|
|
47 |
answers = request.form.getlist('answer')
|
48 |
-
if
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
53 |
session['current_question'] += 1
|
54 |
if session['current_question'] >= len(session['questions']):
|
55 |
return redirect(url_for('results'))
|
@@ -61,7 +71,7 @@ def quiz():
|
|
61 |
return redirect(url_for('results'))
|
62 |
|
63 |
question = session['questions'][session['current_question']]
|
64 |
-
multiple_selection = 'SELECT TWO' in question['question']
|
65 |
elapsed_time = time.time() - session['start_time']
|
66 |
elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
|
67 |
|
|
|
44 |
if request.method == 'POST':
|
45 |
action = request.form.get('action')
|
46 |
if action == 'next':
|
47 |
+
question = session['questions'][session['current_question']]
|
48 |
+
multiple_selection = 'SELECT TWO' in question['question'] or 'SELECT THREE' in question['question']
|
49 |
answers = request.form.getlist('answer')
|
50 |
+
if multiple_selection:
|
51 |
+
required_answers = 2 if 'SELECT TWO' in question['question'] else 3
|
52 |
+
if len(answers) == required_answers:
|
53 |
+
session['answers'].append(answers)
|
54 |
+
correct_answers = [str(int(x) + 1) for x in question['correct']]
|
55 |
+
if set(answers) == set(correct_answers):
|
56 |
+
session['score'] += 1
|
57 |
+
else:
|
58 |
+
if answers:
|
59 |
+
session['answers'].append(answers)
|
60 |
+
correct_answers = [str(int(x) + 1) for x in question['correct']]
|
61 |
+
if set(answers) == set(correct_answers):
|
62 |
+
session['score'] += 1
|
63 |
session['current_question'] += 1
|
64 |
if session['current_question'] >= len(session['questions']):
|
65 |
return redirect(url_for('results'))
|
|
|
71 |
return redirect(url_for('results'))
|
72 |
|
73 |
question = session['questions'][session['current_question']]
|
74 |
+
multiple_selection = 'SELECT TWO' in question['question'] or 'SELECT THREE' in question['question']
|
75 |
elapsed_time = time.time() - session['start_time']
|
76 |
elapsed_time_str = time.strftime('%H:%M:%S', time.gmtime(elapsed_time))
|
77 |
|
templates/quiz.html
CHANGED
@@ -22,12 +22,21 @@
|
|
22 |
<h1>Question {{ question_number }} of {{ total_questions }} - {{ selected_file }} <span id="timer"></span></h1>
|
23 |
<p>{{ question.question }}</p>
|
24 |
<form action="{{ url_for('quiz') }}" method="post">
|
25 |
-
{%
|
26 |
-
|
27 |
-
<
|
28 |
-
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
<br>
|
32 |
{% if show_previous %}
|
33 |
<button type="submit" name="action" value="previous">Previous</button>
|
|
|
22 |
<h1>Question {{ question_number }} of {{ total_questions }} - {{ selected_file }} <span id="timer"></span></h1>
|
23 |
<p>{{ question.question }}</p>
|
24 |
<form action="{{ url_for('quiz') }}" method="post">
|
25 |
+
{% if multiple_selection %}
|
26 |
+
{% for option in question.options %}
|
27 |
+
<label style="display: flex; align-items: center;">
|
28 |
+
<input type="checkbox" name="answer" value="{{ loop.index }}" required>
|
29 |
+
<span>{{ option }}</span>
|
30 |
+
</label><br>
|
31 |
+
{% endfor %}
|
32 |
+
{% else %}
|
33 |
+
{% for option in question.options %}
|
34 |
+
<label style="display: flex; align-items: center;">
|
35 |
+
<input type="radio" name="answer" value="{{ loop.index }}" required>
|
36 |
+
<span>{{ option }}</span>
|
37 |
+
</label><br>
|
38 |
+
{% endfor %}
|
39 |
+
{% endif %}
|
40 |
<br>
|
41 |
{% if show_previous %}
|
42 |
<button type="submit" name="action" value="previous">Previous</button>
|