Sina Media Lab commited on
Commit
a39e202
·
1 Parent(s): cf9666b
Files changed (1) hide show
  1. app.py +19 -25
app.py CHANGED
@@ -168,38 +168,32 @@ with col3:
168
 
169
  st.write(current_question["question"])
170
 
171
- # Use a form to prevent rerun on option selection
172
  with st.form(key=f'question_form_{st.session_state.current_index}'):
173
  selected_answer = st.radio(
174
  "Choose an answer:",
175
  options=current_question['options'],
176
- key=f"question_{st.session_state.current_index}_options",
177
- index=None # No pre-selection
178
  )
179
- submit_button = st.form_submit_button(label="Submit", disabled=st.session_state.submit_disabled)
 
180
 
181
- # Activation logic for buttons based on selection
182
- if selected_answer is not None:
183
  st.session_state.submit_disabled = False
184
- st.session_state.selected_answer = selected_answer
185
- st.experimental_rerun()
186
-
187
- if submit_button and not current_question.get('answered', False):
188
- if st.session_state.selected_answer is None:
189
- st.warning("Please select an answer before submitting.")
190
- else:
191
- # Process the answer
192
- current_question['selected'] = st.session_state.selected_answer
193
- current_question['answered'] = True
194
- st.session_state.module_question_count[selected_module] += 1
195
-
196
- if st.session_state.selected_answer == current_question['correct_answer']:
197
- st.session_state.correct_count += 1
198
- st.session_state.module_correct_count[selected_module] += 1
199
 
200
- st.session_state.submit_disabled = True
201
- st.session_state.next_disabled = False
202
- st.session_state.selected_answer = None
 
 
 
 
 
 
 
 
 
203
 
204
  # Show correct/incorrect feedback after submission
205
  if current_question.get('answered', False):
@@ -215,4 +209,4 @@ if current_question.get('answered', False):
215
  st.write(f"**Explanation:** {current_question['explanation']}")
216
  st.write("**Step-by-Step Solution:**")
217
  for step in current_question['step_by_step_solution']:
218
- st.write(step)
 
168
 
169
  st.write(current_question["question"])
170
 
171
+ # Create the form for the question
172
  with st.form(key=f'question_form_{st.session_state.current_index}'):
173
  selected_answer = st.radio(
174
  "Choose an answer:",
175
  options=current_question['options'],
176
+ key=f"question_{st.session_state.current_index}_options"
 
177
  )
178
+ # Enable submit button when an answer is selected
179
+ submit_button = st.form_submit_button(label="Submit")
180
 
181
+ # Handle button state and answer submission
182
+ if selected_answer:
183
  st.session_state.submit_disabled = False
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
 
185
+ if submit_button and selected_answer:
186
+ # Process the answer
187
+ current_question['selected'] = selected_answer
188
+ current_question['answered'] = True
189
+ st.session_state.module_question_count[selected_module] += 1
190
+
191
+ if selected_answer == current_question['correct_answer']:
192
+ st.session_state.correct_count += 1
193
+ st.session_state.module_correct_count[selected_module] += 1
194
+
195
+ st.session_state.submit_disabled = True
196
+ st.session_state.next_disabled = False
197
 
198
  # Show correct/incorrect feedback after submission
199
  if current_question.get('answered', False):
 
209
  st.write(f"**Explanation:** {current_question['explanation']}")
210
  st.write("**Step-by-Step Solution:**")
211
  for step in current_question['step_by_step_solution']:
212
+ st.write(step)