Sina Media Lab
commited on
Commit
·
1596f6d
1
Parent(s):
9d6157e
Updates
Browse files
app.py
CHANGED
@@ -162,45 +162,29 @@ with col3:
|
|
162 |
|
163 |
st.write(current_question["question"])
|
164 |
|
165 |
-
#
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
st.session_state.correct_count += 1
|
189 |
-
st.session_state.module_correct_count[selected_module] += 1
|
190 |
-
|
191 |
-
# Set answered to true to disable options
|
192 |
-
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
193 |
-
st.session_state.selected_answer = selected_answer
|
194 |
-
|
195 |
-
else:
|
196 |
-
# If already answered, move to the next question
|
197 |
-
new_question = generate_new_question(selected_module, modules[selected_module])
|
198 |
-
st.session_state.questions.append(new_question)
|
199 |
-
st.session_state.current_index = len(st.session_state.questions) - 1
|
200 |
-
st.session_state.answered = False
|
201 |
-
|
202 |
-
# Show correct/incorrect feedback after submission
|
203 |
-
if current_question.get('answered', False):
|
204 |
for option in current_question['options']:
|
205 |
if option == current_question['correct_answer']:
|
206 |
st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)
|
|
|
162 |
|
163 |
st.write(current_question["question"])
|
164 |
|
165 |
+
# Handle the selection of an option and check the answer immediately
|
166 |
+
selected_answer = st.radio(
|
167 |
+
"Choose an answer:",
|
168 |
+
options=current_question['options'],
|
169 |
+
index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
|
170 |
+
key=f"question_{st.session_state.current_index}_options"
|
171 |
+
)
|
172 |
+
|
173 |
+
if selected_answer is not None and not current_question['answered']:
|
174 |
+
# Process the answer
|
175 |
+
current_question['selected'] = selected_answer
|
176 |
+
current_question['answered'] = True
|
177 |
+
st.session_state.module_question_count[selected_module] += 1
|
178 |
+
|
179 |
+
if selected_answer == current_question['correct_answer']:
|
180 |
+
st.session_state.correct_count += 1
|
181 |
+
st.session_state.module_correct_count[selected_module] += 1
|
182 |
+
|
183 |
+
# Set answered to true to disable options
|
184 |
+
st.session_state.questions[st.session_state.current_index]['answered'] = True
|
185 |
+
st.session_state.selected_answer = selected_answer
|
186 |
+
|
187 |
+
# Show correct/incorrect feedback immediately
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
188 |
for option in current_question['options']:
|
189 |
if option == current_question['correct_answer']:
|
190 |
st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)
|