|
import streamlit as st |
|
import importlib |
|
|
|
|
|
module_names = { |
|
"Presentation in bases 2, 10, 8, and 16": "presentation_bases", |
|
"Valid or invalid numbers in each base": "valid_invalid_numbers", |
|
"Conversion with and without fractions among four bases of 10, 2, 8, and 16": "conversion_bases", |
|
"Using grouping techniques for conversion between 2 and 8 and 16": "grouping_techniques", |
|
"Addition in base 2, 8, and 16": "addition_bases", |
|
"2's complement questions": "twos_complement", |
|
"Negative binary numbers": "negative_binary", |
|
"Subtraction in base 2 using 2's complement method": "subtraction_bases", |
|
} |
|
|
|
|
|
st.sidebar.title("Multiple Choice Quiz") |
|
module_name = st.sidebar.radio("Choose a module:", list(module_names.keys())) |
|
|
|
if module_name: |
|
module_file = module_names[module_name] |
|
try: |
|
module = importlib.import_module(f'modules.{module_file}') |
|
generate_question = module.generate_question |
|
question, options, correct_answer, explanation = generate_question() |
|
|
|
st.write(f"**Question:** {question}") |
|
answer = st.radio("Choose an answer:", options) |
|
|
|
if st.button("Submit"): |
|
if answer == correct_answer: |
|
st.success("Correct!", icon="β
") |
|
st.write(f"**Explanation:** {explanation}") |
|
else: |
|
st.error("Incorrect.", icon="β") |
|
st.write(f"**Explanation:** {explanation}") |
|
except ModuleNotFoundError: |
|
st.error(f"The module '{module_name}' was not found. Please select another module.") |
|
|