Sina Media Lab commited on
Commit
3f5191b
·
1 Parent(s): e0f928e
Files changed (1) hide show
  1. app.py +8 -12
app.py CHANGED
@@ -157,11 +157,13 @@ with col3:
157
  st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
158
 
159
  # Option highlighting logic
160
- option_styles = {
161
- 'correct': "background-color:#d4edda;padding:10px;border-radius:5px;",
162
- 'incorrect': "background-color:#f8d7da;padding:10px;border-radius:5px;",
163
- 'default': "padding:10px;border-radius:5px;"
164
- }
 
 
165
 
166
  selected_answer = st.radio(
167
  "Choose an answer:",
@@ -183,10 +185,4 @@ if st.button("Submit"):
183
 
184
  # Retain and highlight the options after submission
185
  for option in current_question['options']:
186
- if current_question['answered']:
187
- if option == current_question['correct']:
188
- st.markdown(f"<div style='{option_styles['correct']}'>{option}</div>", unsafe_allow_html=True)
189
- elif option == current_question['selected']:
190
- st.markdown(f"<div style='{option_styles['incorrect']}'>{option}</div>", unsafe_allow_html=True)
191
- else:
192
- st.markdown(f"<div style='{option_styles['default']}'>{option}</div>", unsafe_allow_html=True)
 
157
  st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
158
 
159
  # Option highlighting logic
160
+ def get_option_style(option):
161
+ if current_question['answered']:
162
+ if option == current_question['correct']:
163
+ return "background-color:#d4edda;padding:10px;border-radius:5px;" # Green background for correct
164
+ elif option == current_question['selected']:
165
+ return "background-color:#f8d7da;padding:10px;border-radius:5px;" # Red background for incorrect
166
+ return "background-color:#f0f0f0;padding:10px;border-radius:5px;" # Gray background by default
167
 
168
  selected_answer = st.radio(
169
  "Choose an answer:",
 
185
 
186
  # Retain and highlight the options after submission
187
  for option in current_question['options']:
188
+ st.markdown(f"<div style='{get_option_style(option)}'>{option}</div>", unsafe_allow_html=True)