Sina Media Lab commited on
Commit
06735cd
·
1 Parent(s): 984a89c
Files changed (1) hide show
  1. app.py +6 -4
app.py CHANGED
@@ -103,6 +103,8 @@ def load_module(module_name):
103
  def generate_new_question(module_name):
104
  module = load_module(module_name)
105
  question_data = module.generate_question()
 
 
106
  return question_data
107
 
108
  def navigate_question(direction):
@@ -135,7 +137,7 @@ st.write(current_question["question"])
135
 
136
  # Option highlighting logic
137
  def get_option_style(option):
138
- if current_question['answered']:
139
  if option == current_question['correct_answer']:
140
  return "background-color:#d4edda;padding:10px;border-radius:5px;" # Green background for correct
141
  elif option == current_question['selected']:
@@ -145,12 +147,12 @@ def get_option_style(option):
145
  selected_answer = st.radio(
146
  "Choose an answer:",
147
  current_question['options'],
148
- index=current_question['options'].index(current_question['selected']) if current_question.get('selected') else None,
149
  key=st.session_state.current_index
150
  )
151
 
152
  if st.button("Submit"):
153
- if not current_question.get('answered'):
154
  current_question['selected'] = selected_answer
155
  current_question['answered'] = True
156
  st.session_state.module_question_count[module_name] += 1
@@ -164,7 +166,7 @@ for option in current_question['options']:
164
  st.markdown(f"<div style='{get_option_style(option)}'>{option}</div>", unsafe_allow_html=True)
165
 
166
  # Show explanation and step-by-step solution
167
- if current_question.get('answered'):
168
  st.write(f"**Explanation:** {current_question['explanation']}")
169
  st.write("**Step-by-Step Solution:**")
170
  for step in current_question['step_by_step_solution']:
 
103
  def generate_new_question(module_name):
104
  module = load_module(module_name)
105
  question_data = module.generate_question()
106
+ # Ensure 'answered' is initialized to False
107
+ question_data['answered'] = False
108
  return question_data
109
 
110
  def navigate_question(direction):
 
137
 
138
  # Option highlighting logic
139
  def get_option_style(option):
140
+ if current_question.get('answered', False): # Use .get() with default False
141
  if option == current_question['correct_answer']:
142
  return "background-color:#d4edda;padding:10px;border-radius:5px;" # Green background for correct
143
  elif option == current_question['selected']:
 
147
  selected_answer = st.radio(
148
  "Choose an answer:",
149
  current_question['options'],
150
+ index=current_question['options'].index(current_question.get('selected', '')) if current_question.get('selected') else None,
151
  key=st.session_state.current_index
152
  )
153
 
154
  if st.button("Submit"):
155
+ if not current_question.get('answered', False): # Check if the question has already been answered
156
  current_question['selected'] = selected_answer
157
  current_question['answered'] = True
158
  st.session_state.module_question_count[module_name] += 1
 
166
  st.markdown(f"<div style='{get_option_style(option)}'>{option}</div>", unsafe_allow_html=True)
167
 
168
  # Show explanation and step-by-step solution
169
+ if current_question.get('answered', False):
170
  st.write(f"**Explanation:** {current_question['explanation']}")
171
  st.write("**Step-by-Step Solution:**")
172
  for step in current_question['step_by_step_solution']: