packages = ["numpy", "matplotlib"] # Math question - Multiplication import math, random, numpy, io, base64 import matplotlib.pyplot as plt import matplotlib.pyplot as plt, io, base64, math import matplotlib.patches as patches from pyscript import document def math_question_1(): # Generating Question and answer num_1 = random.randint(0,12) num_2 = random.randint(0,12) question = (f"{num_1} \u00D7 {num_2} = \u2610") answer1 = num_1*num_2 # Resetting questions and storing values document.getElementById("question_1_equation").innerHTML = question #document.getElementById("feedback_1").innerHTML = "" document.getElementById("answer_1").value = "" document.getElementById("question_1").innerText = str(answer1) return question, answer1 # enabling answer input def answer_question_1(input=None): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] msg = random.choice(positive_response) # Compiling numerical answers user_answer = document.getElementById('answer_1').value correct_answer = int(document.getElementById("question_1").innerText) if not user_answer.isdigit(): document.getElementById('feedback_1').innerHTML = "Please enter digits only" document.getElementById("answer_1").value = "" return user_answer = int(user_answer) # Compiling mistakes if document.getElementById("question_1_attempts").innerHTML == "": document.getElementById("question_1_attempts").innerHTML = 0 else: pass # Checking answer if user_answer == correct_answer: past_question_string = f"✅ {document.getElementById("question_1_equation").innerHTML} {correct_answer} (mistakes : {document.getElementById("question_1_attempts").innerHTML})
" document.getElementById('feedback_1').innerHTML = f"{msg}" document.getElementById('past_questions').innerHTML += past_question_string.replace('\u2610', "") document.getElementById("question_1_attempts").innerHTML = "" math_question_1() else: document.getElementById('feedback_1').innerHTML ="Try again" document.getElementById("answer_1").value = "" document.getElementById("question_1_attempts").innerHTML = int(document.getElementById("question_1_attempts").innerHTML)+1 ###################################################################### # Math question 2 - Division def math_question_2(): num_1 = random.randint(1,12)# prevents 0/0 num_2 = random.randint(0,12) num_3 = num_1*num_2 question = f"{num_3} \u00F7 {num_1} = \u2610" # Resetting questions and storing values document.getElementById("question_2_equation").innerHTML = question document.getElementById("answer_2").value = "" document.getElementById("question_2").innerText = str(num_2) return question def answer_question_2(): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] num_2 = int(document.getElementById('question_2').innerText) user_answer = document.getElementById('answer_2').value if not user_answer.isdigit(): document.getElementById('feedback_2').innerHTML = "Please enter digits only" document.getElementById("answer_2").value = "" return user_answer = int(user_answer) # Compiling mistakes if document.getElementById("question_2_attempts").innerHTML == "": document.getElementById("question_2_attempts").innerHTML = 0 else: pass if user_answer == int(document.getElementById("question_2").innerText): msg = random.choice(positive_response) document.getElementById('feedback_2').innerHTML = f"{msg}" past_question_string = f"✅ {document.getElementById("question_2_equation").innerHTML} {num_2} (mistakes : {document.getElementById("question_2_attempts").innerHTML})
" document.getElementById('past_questions_2').innerHTML += past_question_string.replace('\u2610', "") document.getElementById("question_2_attempts").innerHTML = "" math_question_2() else: document.getElementById('feedback_2').innerHTML ="Try again" document.getElementById("answer_2").value = "" document.getElementById("question_2_attempts").innerHTML = int(document.getElementById("question_2_attempts").innerHTML)+1 ###################################################################### # Math question - Mixed numbers def math_question_3(): num_1 = random.randint(10,25) num_2 = random.randint(2,9) suffix_dict = {2:"half/halves", 3:"third/s", 4:"quarter/s", 5:"fifth/s", 6:"sixth/s", 7:'sevenths', 8: "eighths", 9: 'ninths'} document.getElementById('feedback_3') == "stage 1" # Forcing fraction while num_1 % num_2 == 0 : num_2 = random.randint(1,9) question = f"{num_1} {suffix_dict[num_2]}" # Producing answer remainder = num_1 % num_2 quotient = num_1-remainder factor = quotient/num_2 answer = f"{int(factor)} {remainder}/{num_2}" document.getElementById("question_3_answer").innerText = answer simplify_check = math.gcd(num_2,remainder) if remainder: simplified_answer = f"{int(factor)} {int((remainder/simplify_check))}/{(int(num_2/simplify_check))}" document.getElementById("question_3_simplified_answer").innerText = f"{simplified_answer}" else: document.getElementById("question_3_simplified_answer").innerText = "" # Resetting questions and storing values document.getElementById("question_3_equation").innerHTML = question #document.getElementById("feedback_3").innerHTML = "" document.getElementById("answer_3").value = "" def answer_question_3(): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] # Compiling all answers user_answer = document.getElementById("answer_3").value answer = document.getElementById("question_3_answer").innerHTML simplified_answer = document.getElementById("question_3_simplified_answer").innerHTML # Compiling mistakes made if document.getElementById("question_3_attempts").innerHTML == "": document.getElementById("question_3_attempts").innerHTML = 0 else: pass if user_answer == simplified_answer: document.getElementById("past_questions_3").innerHTML += f"✅ {document.getElementById("question_3_equation").innerHTML} = {simplified_answer} (mistakes : {document.getElementById("question_3_attempts").innerHTML})
" document.getElementById("feedback_3").innerHTML = f"{positive_response[random.randint(0, len(positive_response)-1)]}" document.getElementById("question_3_attempts").innerHTML = "" math_question_3() elif user_answer == answer and simplified_answer != "": document.getElementById("past_questions_3").innerHTML += f"❎ {document.getElementById("question_3_equation").innerHTML} = {answer} which equals {simplified_answer} (mistakes : {document.getElementById("question_3_attempts").innerHTML})
" document.getElementById("feedback_3").innerHTML = f"{positive_response[random.randint(0, len(positive_response)-1)]}" document.getElementById("question_3_attempts").innerHTML = "" math_question_3() elif user_answer == answer: document.getElementById("past_questions_3").innerHTML += f"✅ Correct Answer:{answer} (mistakes : {document.getElementById("question_3_attempts").innerHTML}
" document.getElementById("feedback_3").innerHTML = f"{positive_response[random.randint(0, len(positive_response)-1)]}" document.getElementById("question_3_attempts").innerHTML = "" math_question_3() else: document.getElementById('feedback_3').innerHTML = "Try again" document.getElementById("answer_3").value = "" document.getElementById("question_3_attempts").innerHTML = f"{int(document.getElementById("question_3_attempts").innerHTML) + 1}" ###################################################################### def math_question_4(): distance_units = {'millimeters (mm)':[1, 'mm' ], 'centimeters (cm)':[10, 'cm'], 'meters (m)':[1000, 'm'], 'kilometers (km)':[1000000, 'Km']} volume_units = {'milliliters (ml)':[1, 'ml'], 'Liters (L)':[1000, "L"]} mass_units = {'miligrams (mg)':[1, 'mg'], 'grams (g)':[1000, 'g'], 'kilograms (Kg)':[1000000, "kg"], 'tonnes (T)':[1000000000, "T"]} measurements = [distance_units, volume_units, mass_units] selection = random.choice(measurements) selection_keys = list(selection.keys()) # Removing selected unit selection_1 = random.choice(selection_keys) selection_keys.remove(selection_1) # Choosing second unit selection_2 = random.choice(selection_keys) # Selecting magnitude selection_1_int = random.randint(1, 999) # Storing selection and generating question document.getElementById('question_4_equation').innerHTML = f"Convert {str(selection_1_int)} {selection_1} to {selection_2}, don't forget to answer with units" # Storing answer correct_answer = (selection_1_int*int(selection.get(selection_1)[0]))/int(selection.get(selection_2)[0]) if str(correct_answer).endswith('.0'): correct_answer = round(correct_answer) else: pass document.getElementById('question_4').innerHTML = f"{correct_answer} {selection.get(selection_2)[1]}" def answer_question_4(input=None): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] msg = random.choice(positive_response) user_answer = document.getElementById("answer_4").value correct_answer = document.getElementById("question_4").innerHTML # Compiling mistakes if document.getElementById("question_4_attempts").innerHTML == "": document.getElementById("question_4_attempts").innerHTML = 0 else: pass # Checking answer if user_answer.replace(' ', '').lower() == correct_answer.replace(' ', '').lower(): simple_question = document.getElementById("question_4_equation").innerHTML simple_question.replace('Convert ', "") past_question_string = f"✅ {simple_question} = {correct_answer} (mistakes : {document.getElementById("question_4_attempts").innerHTML})
" document.getElementById('feedback_4').innerHTML = f"{msg}" document.getElementById('past_questions_4').innerHTML += f"{past_question_string}" document.getElementById("question_4_attempts").innerHTML = "" document.getElementById("answer_4").value = "" math_question_4() else: document.getElementById('feedback_4').innerHTML = "Try again" document.getElementById("answer_4").value = "" document.getElementById("question_4_attempts").innerHTML = int(document.getElementById("question_4_attempts").innerHTML)+1 ###################################################################### def math_question_5(input=None): # Generating random linear quation m = random.randint(-9,9) c = random.randint(-10, 10) # Generating random two coordinates in the function x1 = random.randint(-10,10) x2 = random.randint(-10,10) if x1 == x2: while x1 == x2: x2 = random.randint(-10,10) y1 = m*x1+c y2 = m*x2+c # Generating image m = random.randint(-9,9) c = random.randint(-10, 10) # Generating random two coordinates in the function x1 = random.randint(-10,10) x2 = random.randint(-10,10) if x1 == x2: while x1 == x2: x2 = random.randint(-10,10) y1 = m*x1+c y2 = m*x2+c coord_1=(x1, y1) coord_2=(x2, y2) # Generating image # Define the equation y = 2x + 3 x = numpy.linspace(-20, 20, 20) # 100 points from -10 to 10 y = m*x + c # Create the plot plt.figure(figsize=(6, 4)) plt.plot(x, y, color="blue", zorder=1) plt.scatter(x1, y1, color='black', zorder = 2) plt.scatter(x2, y2, color='black', zorder = 2) plt.annotate(f'({x1},{y1})',[x1,y1]) plt.annotate(f'({x2},{y2})',[x2,y2]) # Add axis lines through the origin plt.axhline(0, color='black', linewidth=1) # x-axis plt.axvline(0, color='black', linewidth=1) # y-axis # Labels, title plt.xlabel("x") plt.ylabel("y") plt.title("Find the equation of the below line") plt.grid(True) # Convert to base64 image buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) img_base64 = base64.b64encode(buf.read()).decode('utf-8') buf.close() # Generating question & presenting image document.getElementById('question_5_hint').innerHTML = "Reminder that y = mx + c where the gradient (m) = rise/run and the constant (c) = y-intercept at the cordinate (0, ?)" document.getElementById('question_5_equation').innerHTML = f"Find the equation of the straight line passing through the points ({x1}, {y1}) and ({x2}, {y2})" document.getElementById("question_5_plot").innerHTML = f'' #Storing correct answer document.getElementById('question_5').innerHTML = f"y={m}x + {c}" def answer_question_5(input=None): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] msg = random.choice(positive_response) user_input_5 = document.getElementById("answer_5").value correct_answer_5 = document.getElementById('question_5').innerHTML if document.getElementById("question_5_attempts").innerHTML == "": document.getElementById("question_5_attempts").innerHTML = 0 else: pass # Checking answer if user_input_5.replace(' ', '') == correct_answer_5.replace(' ', ''): simple_question = document.getElementById("question_5_equation").innerHTML simple_question.replace('Find the equation of the straight line passing through the points ', "") past_question_string = f"✅ {simple_question} = {correct_answer_5} (mistakes : {document.getElementById("question_5_attempts").innerHTML})
" document.getElementById('feedback_5').innerHTML = f"{msg}" document.getElementById('past_questions_5').innerHTML += f"{past_question_string}" document.getElementById("question_5_attempts").innerHTML = "" document.getElementById("answer_5").value = "" math_question_5() else: document.getElementById('feedback_5').innerHTML = "Try again" document.getElementById("answer_5").value = "" document.getElementById("question_5_attempts").innerHTML = int(document.getElementById("question_5_attempts").innerHTML)+1 ###################################################################### def math_question_6(input=None): degrees_1 = random.randint(0, 200) degrees_2 = random.randint(0, 200) angle_1 = round(math.radians(degrees_1), 3) angle_2 = round(math.radians(degrees_2), 3) # setting answer conitions condition = (degrees_2-degrees_1) % 360 # Preventing same angle if angle_1 == angle_2: while angle_1 == angle_2: angle_2 = round(math.radians(random.randint(0, 350)), 3) # Plotting image fig, ax = plt.subplots() plt.scatter([0, math.cos(angle_1)], [0, math.sin(angle_1)], color="black", zorder=2) plt.plot([0, math.cos(angle_1)], [0, math.sin(angle_1)], color = 'black', zorder=2) plt.scatter([0, math.cos(angle_2)], [0, math.sin(angle_2)], color="black", zorder=2) plt.plot([0, math.cos(angle_2)], [0, math.sin(angle_2)], color = 'black', zorder=2) plt.scatter(0,0, s = 30000) if condition != 90: arc = patches.Arc((0, 0), 1, 1, color='black', theta1 = degrees_1, theta2 = degrees_2, zorder=2) ax.add_patch(arc) else: size = 0.2 a1_x, a1_y = size * math.cos(angle_1), size * math.sin(angle_1) a2_x, a2_y = size * math.cos(angle_2), size * math.sin(angle_2) # Point connecting the two perpendicular segments intercept_x, intercept_y = a1_x + a2_x, a1_y + a2_y # Draw the small right-angle square plt.plot([a1_x, intercept_x], [a1_y, intercept_y], color='black', zorder=2) plt.plot([a2_x, intercept_x], [a2_y, intercept_y], color='black', zorder=2) # Labels, title plt.xlim([-1.5,1.5]) plt.ylim([-1.5,1.5]) plt.grid(False) plt.gca().set_aspect('equal', adjustable='box') plt.axis('off') # Convert to base64 image buf = io.BytesIO() plt.savefig(buf, format='png', bbox_inches='tight') buf.seek(0) img_base64 = base64.b64encode(buf.read()).decode('utf-8') buf.close() # Generating question & presenting image document.getElementById('question_6_equation').innerHTML = f"What kind of angle is the below?" document.getElementById("question_6_plot").innerHTML = f'' # setting answer conitions condition = (degrees_2-degrees_1) % 360 if condition < 90: answer = " acute" elif condition == 90: answer = " right" elif condition > 90 and condition < 180: answer = "obtuse" elif condition > 120: answer = "reflex" document.getElementById("question_6").innerHTML = f"{answer} {condition}" def answer_question_6(input=None): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] msg = random.choice(positive_response) user_input_6 = document.getElementById("answer_6").value user_input_6 = user_input_6.replace('angle', '') user_input_6 = user_input_6.replace(' ', '') correct_answer_6 = document.getElementById('question_6').innerHTML if document.getElementById("question_6_attempts").innerHTML == "": document.getElementById("question_6_attempts").innerHTML = 0 else: pass if user_input_6.lower() == correct_answer_6[:6].replace(' ', ""): simple_question = f"{correct_answer_6[7:]}" past_question_string = f"✅ {simple_question} = {correct_answer_6} (mistakes : {document.getElementById("question_6_attempts").innerHTML})
" document.getElementById('feedback_6').innerHTML = f"{msg}" document.getElementById('past_questions_6').innerHTML += f"{past_question_string}" document.getElementById("question_6_attempts").innerHTML = "" document.getElementById("answer_6").value = "" math_question_6() else: document.getElementById('feedback_6').innerHTML = "Try again" document.getElementById("answer_6").value = "" document.getElementById("question_6_attempts").innerHTML = int(document.getElementById("question_6_attempts").innerHTML)+1 ###################################################################### def math_question_7(input=None): f1_num, f1_denom = random.randint(1, 10), random.randint(1, 10) f2_num, f2_denom = random.randint(1, 10), random.randint(1, 10) frac1 = f1_num/f1_denom frac2 = f2_num/f2_denom if max(frac1, frac2) == frac1: answer = f"a - {f1_num}/{f1_denom} is bigger than {f2_num}/{f2_denom}" else: answer = f"b - {f2_num}/{f2_denom} is bigger than {f1_num}/{f1_denom}" document.getElementById('question_7_equation').innerHTML = f"Which is larger,
A {f1_num}/{f1_denom}
or
B {f2_num}/{f2_denom}?" document.getElementById("question_7").innerHTML = f"{answer}" def answer_question_7(input = None): positive_response = ['Well done!!', 'Thats right!', 'Knew you could do it!', 'Correct!', "You're on fire!"] msg = random.choice(positive_response) user_input_7 = document.getElementById("answer_7").value user_input_7 = user_input_7.replace(' ', '').lower() correct_answer_7 = document.getElementById('question_7').innerHTML if document.getElementById("question_7_attempts").innerHTML == "": document.getElementById("question_7_attempts").innerHTML = 0 else: pass if user_input_7 == correct_answer_7[:1]: simple_question = f"{correct_answer_7}" past_question_string = f"✅ {simple_question} (mistakes : {document.getElementById("question_7_attempts").innerHTML})
" document.getElementById('feedback_7').innerHTML = f"{msg}" document.getElementById('past_questions_7').innerHTML += f"{past_question_string}" document.getElementById("question_7_attempts").innerHTML = "" document.getElementById("answer_7").value = "" math_question_7() else: document.getElementById('feedback_7').innerHTML = "Try again" document.getElementById("answer_7").value = "" document.getElementById("question_7_attempts").innerHTML = int(document.getElementById("question_7_attempts").innerHTML)+1 ###################################################################### def check_enter(evt): if evt.key == "Enter" and document.getElementById("answer_1").value != "": answer_question_1(input) elif evt.key == "Enter" and document.getElementById("answer_2").value != "": answer_question_2() elif evt.key == "Enter" and document.getElementById("answer_3").value != "": answer_question_3() elif evt.key == "Enter" and document.getElementById("answer_4").value != "": answer_question_4() elif evt.key == "Enter" and document.getElementById("answer_5").value != "": answer_question_5() elif evt.key == "Enter" and document.getElementById("answer_6").value != "": answer_question_6() elif evt.key == "Enter" and document.getElementById("answer_6").value != "": answer_question_7() document.getElementById('question_5_hint').attributes globals()["math_question_1"] = math_question_1 globals()["answer_question_1"] = answer_question_1 globals()["math_question_2"] = math_question_2 globals()["answer_question_2"] = answer_question_2 globals()["math_question_3"] = math_question_3 globals()["answer_question_3"] = answer_question_3 globals()["math_question_4"] = math_question_4 globals()["answer_question_4"] = answer_question_4 globals()["math_question_5"] = math_question_5 globals()["answer_question_5"] = answer_question_5 globals()["math_question_6"] = math_question_6 globals()["answer_question_6"] = answer_question_6 globals()["math_question_7"] = math_question_7 globals()["answer_question_7"] = answer_question_7 globals()["check_enter"] = check_enter math_question_1() math_question_2() math_question_3() math_question_4() math_question_5() math_question_6() math_question_7()

Multiplication Practice

Division Practice

Mixed numbers Practice

A mixed number is composed of a whole number and the remaining fraction. See the below example:
3/2 is 1 and a half
◖ ◖ ◖
or...
◖◗ ◖
If we think of these as pieces of a circle then we can see that 3 pieces will give 1 complete circle with one half as the remainder
◖◗, ◖
So we have a whole number of 1, and the remainder of 1 becomes the new numerator.
3/2 = One and one half, or simply 1 1/2
Please practice simplifying the following to make a mixed number:

Measurement Practice

Angle Types

Fraction comparissons

Linear Algebra