Sina Media Lab commited on
Commit
eda4dad
Β·
1 Parent(s): 74a6085
app.py CHANGED
@@ -128,7 +128,10 @@ def generate_new_question(category_name, module_name, module):
128
  # Load all modules dynamically
129
  modules = load_modules()
130
 
131
- # Streamlit interface
 
 
 
132
  st.sidebar.title("Quiz Categories")
133
  selected_category = st.sidebar.selectbox("Choose a category:", list(modules.keys()))
134
 
@@ -140,6 +143,15 @@ if selected_category:
140
  selected_module_data = module_data
141
  break
142
 
 
 
 
 
 
 
 
 
 
143
  if selected_module != st.session_state.current_module:
144
  st.session_state.current_module = selected_module
145
  st.session_state.current_index = len(st.session_state.questions) # Continue numbering from previous questions
@@ -156,35 +168,6 @@ if selected_category:
156
 
157
  current_question = st.session_state.current_question
158
 
159
- # Title header with rounded corners and margin
160
- st.markdown(
161
- """
162
- <div style='background-color: #D3D3D3; padding: 10px; border-radius: 10px; text-align: center; color: black; margin-top: 20px; position: relative;'>
163
- <h3 style='margin: 0;'>Magic Math Quiz!</h3>
164
- <h6 style='margin: 0; font-size: 10px;'><a href="https://ghassem.com" target="_blank" style="color: black; text-decoration: none;'>By Ghassem Tofighi</a></h6>
165
- <div style='position: absolute; right: 10px; top: 10px;'>
166
- <button id="pdf-button" style='font-size: 10px;'>
167
- Download PDF Report πŸ“„
168
- </button>
169
- </div>
170
- </div>
171
- """, unsafe_allow_html=True)
172
-
173
- # Disable PDF download button initially if no questions have been answered
174
- pdf_button_disabled = not any(q['answered'] for q in st.session_state.questions)
175
- st.write('<script>document.getElementById("pdf-button").disabled = {};</script>'.format(pdf_button_disabled), unsafe_allow_html=True)
176
-
177
- if not pdf_button_disabled:
178
- pdf = generate_pdf_report()
179
- st.session_state.pdf_data = pdf # Reset PDF cache
180
- st.download_button(
181
- label="Download PDF Report πŸ“„",
182
- data=st.session_state.pdf_data,
183
- file_name="quiz_report.pdf",
184
- mime="application/pdf",
185
- disabled=pdf_button_disabled
186
- )
187
-
188
  # Display module title and description with a larger font for description
189
  st.markdown(f"### {selected_module_data['title']}")
190
  st.markdown(f"<span style='font-size: 14px;'>{selected_module_data['description']}</span>", unsafe_allow_html=True)
 
128
  # Load all modules dynamically
129
  modules = load_modules()
130
 
131
+ # Streamlit sidebar
132
+ st.sidebar.title("Magic Math Quiz!")
133
+ st.sidebar.markdown("<h6 style='font-size: 10px;'><a href='https://ghassem.com' target='_blank' style='color: black; text-decoration: none;'>By Ghassem Tofighi</a></h6>", unsafe_allow_html=True)
134
+
135
  st.sidebar.title("Quiz Categories")
136
  selected_category = st.sidebar.selectbox("Choose a category:", list(modules.keys()))
137
 
 
143
  selected_module_data = module_data
144
  break
145
 
146
+ # Display PDF report link
147
+ if any(q['answered'] for q in st.session_state.questions):
148
+ pdf = generate_pdf_report()
149
+ st.session_state.pdf_data = pdf # Reset PDF cache
150
+ st.markdown(
151
+ f"<a href='#' download='quiz_report.pdf' style='font-size: 10px;' onclick='document.getElementById(\"pdf-link\").click();'>Download PDF Report</a>",
152
+ unsafe_allow_html=True
153
+ )
154
+
155
  if selected_module != st.session_state.current_module:
156
  st.session_state.current_module = selected_module
157
  st.session_state.current_index = len(st.session_state.questions) # Continue numbering from previous questions
 
168
 
169
  current_question = st.session_state.current_question
170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
  # Display module title and description with a larger font for description
172
  st.markdown(f"### {selected_module_data['title']}")
173
  st.markdown(f"<span style='font-size: 14px;'>{selected_module_data['description']}</span>", unsafe_allow_html=True)
modules/counting/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ # This file can be left empty or used to import specific functions or variables from the module files.
modules/counting/addition_bases.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modules/numbering_system/addition_bases.py
2
+
3
+ title = "Addition in Various Bases"
4
+ description = "This module covers addition operations in bases like binary, octal, and hexadecimal."
5
+
6
+ def generate_question():
7
+ import random
8
+
9
+ # Choose a base and corresponding valid digits
10
+ base = random.choice([2, 8, 16])
11
+ digits = '01' if base == 2 else '01234567' if base == 8 else '0123456789ABCDEF'
12
+
13
+ # Generate two valid numbers for the selected base
14
+ num1 = ''.join(random.choice(digits) for _ in range(3))
15
+ num2 = ''.join(random.choice(digits) for _ in range(3))
16
+
17
+ def add_numbers(num1, num2, base):
18
+ # Perform the addition in the correct base
19
+ return hex(int(num1, base) + int(num2, base))[2:].upper() if base == 16 else \
20
+ oct(int(num1, base) + int(num2, base))[2:] if base == 8 else \
21
+ bin(int(num1, base) + int(num2, base))[2:] if base == 2 else \
22
+ str(int(num1) + int(num2))
23
+
24
+ correct_answer = add_numbers(num1, num2, base)
25
+ options = [correct_answer]
26
+
27
+ # Generate incorrect answers
28
+ while len(options) < 4:
29
+ invalid_answer = ''.join(random.choice(digits) for _ in range(4))
30
+ if invalid_answer != correct_answer:
31
+ options.append(invalid_answer)
32
+
33
+ random.shuffle(options)
34
+
35
+ question = f"Add the numbers {num1} and {num2} in base {base}."
36
+ explanation = f"The sum of {num1} and {num2} in base {base} is {correct_answer}."
37
+ step_by_step_solution = [
38
+ f"Step 1: Convert the numbers {num1} and {num2} to base 10.",
39
+ "Step 2: Add the numbers in base 10.",
40
+ f"Step 3: Convert the sum back to base {base}."
41
+ ]
42
+
43
+ return {
44
+ "question": question,
45
+ "options": options,
46
+ "correct_answer": correct_answer,
47
+ "explanation": explanation,
48
+ "step_by_step_solution": step_by_step_solution
49
+ }
modules/counting/config.py ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ title = "Counting"
2
+ description = "This category covers various operations and concepts in different counting concept."