Sina Media Lab commited on
Commit
b2ea00a
·
1 Parent(s): 8a51ec9
Files changed (1) hide show
  1. app.py +23 -32
app.py CHANGED
@@ -172,38 +172,29 @@ with col3:
172
 
173
  st.write(current_question["question"])
174
 
175
- # Create the form for the question
176
- with st.form(key=f'question_form_{st.session_state.current_index}'):
177
- selected_answer = st.radio(
178
- "Choose an answer:",
179
- options=current_question['options'],
180
- index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
181
- key=f"question_{st.session_state.current_index}_options"
182
- )
183
-
184
- submit_button = st.form_submit_button(label="Submit")
185
-
186
- # Handle button state and answer submission
187
- if submit_button:
188
- if selected_answer is None:
189
- st.warning("Please select an option before submitting.")
190
- else:
191
- if not current_question['answered']:
192
- # Process the answer
193
- current_question['selected'] = selected_answer
194
- current_question['answered'] = True
195
- st.session_state.module_question_count[selected_module] += 1
196
-
197
- if selected_answer == current_question['correct_answer']:
198
- st.session_state.correct_count += 1
199
- st.session_state.module_correct_count[selected_module] += 1
200
-
201
- # Set answered to true to disable options
202
- st.session_state.questions[st.session_state.current_index]['answered'] = True
203
- st.session_state.selected_answer = selected_answer
204
-
205
- # Show correct/incorrect feedback after submission
206
- if current_question.get('answered', False):
207
  for option in current_question['options']:
208
  if option == current_question['correct_answer']:
209
  st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)
 
172
 
173
  st.write(current_question["question"])
174
 
175
+ # Handle the selection of an option and check the answer immediately
176
+ selected_answer = st.radio(
177
+ "Choose an answer:",
178
+ options=current_question['options'],
179
+ index=current_question['options'].index(current_question['selected']) if current_question['answered'] else None,
180
+ key=f"question_{st.session_state.current_index}_options"
181
+ )
182
+
183
+ if selected_answer is not None and not current_question['answered']:
184
+ # Process the answer
185
+ current_question['selected'] = selected_answer
186
+ current_question['answered'] = True
187
+ st.session_state.module_question_count[selected_module] += 1
188
+
189
+ if selected_answer == current_question['correct_answer']:
190
+ st.session_state.correct_count += 1
191
+ st.session_state.module_correct_count[selected_module] += 1
192
+
193
+ # Set answered to true to disable options
194
+ st.session_state.questions[st.session_state.current_index]['answered'] = True
195
+ st.session_state.selected_answer = selected_answer
196
+
197
+ # Show correct/incorrect feedback immediately
 
 
 
 
 
 
 
 
 
198
  for option in current_question['options']:
199
  if option == current_question['correct_answer']:
200
  st.markdown(f"<span style='color:green;'>{option} ✅</span>", unsafe_allow_html=True)