File size: 1,623 Bytes
7ba3b4e
d924141
 
 
 
 
 
 
 
 
 
 
 
2a56f14
 
 
d924141
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import streamlit as st
import importlib

# List of available modules
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",
}

# Streamlit interface
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.")