Sina Media Lab
commited on
Commit
Β·
0743bdc
1
Parent(s):
f63a29c
Updates
Browse files
app.py
CHANGED
@@ -143,14 +143,28 @@ with col3:
|
|
143 |
# Display the current question
|
144 |
st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
if current_question['answered']:
|
147 |
for option in current_question['options']:
|
148 |
if option == current_question['correct']:
|
149 |
-
st.
|
150 |
elif option == current_question['selected']:
|
151 |
-
st.
|
152 |
else:
|
153 |
st.write(option)
|
|
|
154 |
st.markdown(
|
155 |
f"""
|
156 |
<div style='border: 2px solid #ccc; padding: 15px;'>
|
@@ -159,16 +173,3 @@ if current_question['answered']:
|
|
159 |
""",
|
160 |
unsafe_allow_html=True
|
161 |
)
|
162 |
-
else:
|
163 |
-
selected_answer = st.radio("Choose an answer:", current_question['options'], key=st.session_state.current_index)
|
164 |
-
if st.button("Submit"):
|
165 |
-
if selected_answer:
|
166 |
-
current_question['selected'] = selected_answer
|
167 |
-
current_question['answered'] = True
|
168 |
-
st.session_state.module_question_count[module_name] += 1
|
169 |
-
|
170 |
-
if selected_answer == current_question['correct']:
|
171 |
-
st.session_state.correct_count += 1
|
172 |
-
st.session_state.module_correct_count[module_name] += 1
|
173 |
-
|
174 |
-
# Streamlit will automatically update the UI after state changes
|
|
|
143 |
# Display the current question
|
144 |
st.write(f"**Question {st.session_state.current_index + 1}:** {current_question['question']}")
|
145 |
|
146 |
+
selected_answer = st.radio("Choose an answer:", current_question['options'], index=current_question['options'].index(current_question['selected']) if current_question['selected'] else None, key=st.session_state.current_index)
|
147 |
+
|
148 |
+
if st.button("Submit"):
|
149 |
+
if not current_question['answered']:
|
150 |
+
current_question['selected'] = selected_answer
|
151 |
+
current_question['answered'] = True
|
152 |
+
st.session_state.module_question_count[module_name] += 1
|
153 |
+
|
154 |
+
if selected_answer == current_question['correct']:
|
155 |
+
st.session_state.correct_count += 1
|
156 |
+
st.session_state.module_correct_count[module_name] += 1
|
157 |
+
|
158 |
+
# Highlight the correct and incorrect answers
|
159 |
if current_question['answered']:
|
160 |
for option in current_question['options']:
|
161 |
if option == current_question['correct']:
|
162 |
+
st.markdown(f"<div style='background-color:#d4edda;padding:10px;border-radius:5px;'>β {option}</div>", unsafe_allow_html=True)
|
163 |
elif option == current_question['selected']:
|
164 |
+
st.markdown(f"<div style='background-color:#f8d7da;padding:10px;border-radius:5px;'>β {option}</div>", unsafe_allow_html=True)
|
165 |
else:
|
166 |
st.write(option)
|
167 |
+
|
168 |
st.markdown(
|
169 |
f"""
|
170 |
<div style='border: 2px solid #ccc; padding: 15px;'>
|
|
|
173 |
""",
|
174 |
unsafe_allow_html=True
|
175 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|