Added latex and cleaned wording on all basic_math generators

This commit is contained in:
lukew3
2020-12-17 22:18:50 -05:00
parent 9842169143
commit 42dd6c368c
8 changed files with 42 additions and 26 deletions

View File

@@ -1,13 +1,16 @@
from .__init__ import * from .__init__ import *
def absoluteDifferenceFunc(maxA=100, maxB=100): def absoluteDifferenceFunc(maxA=100, maxB=100, style='raw'):
a = random.randint(-1 * maxA, maxA) a = random.randint(-1 * maxA, maxA)
b = random.randint(-1 * maxB, maxB) b = random.randint(-1 * maxB, maxB)
absDiff = abs(a - b) absDiff = abs(a - b)
problem = "Absolute difference between numbers " + \ if style == 'latex':
str(a) + " and " + str(b) + " = " problem = "\\(|" + str(a) + "-" + str(b) + "|=\\)"
solution = f"\\({absDiff}\\)"
else:
problem = "|" + str(a) + "-" + str(b) + "|="
solution = absDiff solution = absDiff
return problem, solution return problem, solution

View File

@@ -1,7 +1,7 @@
from .__init__ import * from .__init__ import *
def compareFractionsFunc(maxVal=10): def compareFractionsFunc(maxVal=10, style='raw'):
a = random.randint(1, maxVal) a = random.randint(1, maxVal)
b = random.randint(1, maxVal) b = random.randint(1, maxVal)
c = random.randint(1, maxVal) c = random.randint(1, maxVal)
@@ -22,6 +22,9 @@ def compareFractionsFunc(maxVal=10):
else: else:
solution = "=" solution = "="
if style == 'latex':
problem = f"Which symbol represents the comparison between \\(\\frac{{{a}}}{{{b}}}\\) and \\(\\frac{{{c}}}{{{d}}}\\)?"
else:
problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?" problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?"
return problem, solution return problem, solution

View File

@@ -1,11 +1,15 @@
from .__init__ import * from .__init__ import *
def cubeRootFunc(minNo=1, maxNo=1000): def cubeRootFunc(minNo=1, maxNo=1000, style='raw'):
b = random.randint(minNo, maxNo) b = random.randint(minNo, maxNo)
a = b**(1 / 3) a = b**(1 / 3)
problem = "cuberoot of " + str(b) + " upto 2 decimal places is:" if style == 'latex':
problem = f"\\(\\sqrt[3]{{{b}}}=\\)"
solution = "\\(" + str(round(a, 2)) + "\\)"
else:
problem = "What is the cube root of " + str(b) + " up to 2 decimal places?"
solution = str(round(a, 2)) solution = str(round(a, 2))
return problem, solution return problem, solution

View File

@@ -1,10 +1,14 @@
from .__init__ import * from .__init__ import *
def exponentiationFunc(maxBase=20, maxExpo=10): def exponentiationFunc(maxBase=20, maxExpo=10, style='raw'):
base = random.randint(1, maxBase) base = random.randint(1, maxBase)
expo = random.randint(1, maxExpo) expo = random.randint(1, maxExpo)
if style == 'latex':
problem = f"\\({base}^{{{expo}}}\\)"
solution = "\\(" + str(base**expo) + "\\)"
else:
problem = f"{base}^{expo} =" problem = f"{base}^{expo} ="
solution = str(base**expo) solution = str(base**expo)
return problem, solution return problem, solution

View File

@@ -3,18 +3,18 @@ from .__init__ import *
def isprime(max_a=100): def isprime(max_a=100):
a = random.randint(2, max_a) a = random.randint(2, max_a)
problem = a problem = f"Is {a} prime?"
if a == 2: if a == 2:
solution = True solution = "Yes"
return (problem, solution) return (problem, solution)
if a % 2 == 0: if a % 2 == 0:
solution = False solution = "No"
return (problem, solution) return (problem, solution)
for i in range(3, a // 2 + 1, 2): for i in range(3, a // 2 + 1, 2):
if a % i == 0: if a % i == 0:
solution = False solution = "No"
return (problem, solution) return (problem, solution)
solution = True solution = "Yes"
return (problem, solution) return (problem, solution)

View File

@@ -7,7 +7,7 @@ def percentageFunc(maxValue=99, maxpercentage=99):
problem = f"What is {a}% of {b}?" problem = f"What is {a}% of {b}?"
percentage = a / 100 * b percentage = a / 100 * b
formatted_float = "{:.2f}".format(percentage) formatted_float = "{:.2f}".format(percentage)
solution = f"Required percentage = {formatted_float}%" solution = f"{formatted_float}"
return problem, solution return problem, solution

View File

@@ -1,15 +1,17 @@
from .__init__ import * from .__init__ import *
def powerOfPowersFunc(maxBase=50, maxPower=10): def powerOfPowersFunc(maxBase=50, maxPower=10, style='raw'):
base = random.randint(1, maxBase) base = random.randint(1, maxBase)
power1 = random.randint(1, maxPower) power1 = random.randint(1, maxPower)
power2 = random.randint(1, maxPower) power2 = random.randint(1, maxPower)
step = power1 * power2 step = power1 * power2
problem = "The {base}^{power1}^{power2} = ".format(base=base, if style == 'latex':
power1=power1, problem = "Simplify \\(" + str(base) + "^{" + str(power1) + "^{" + str(power2) + "}}\\)"
power2=power2) solution = f"\\({base}^{{{step}}}\\)"
else:
problem = f"Simplify {base}^{power1}^{power2}="
solution = str(base) + '^' + str(step) solution = str(base) + '^' + str(step)
return problem, solution return problem, solution

View File

@@ -1,4 +1,4 @@
from mathgenerator import mathgen from mathgenerator import mathgen
for _ in range(100): for _ in range(100):
print(mathgen.genById(28, style='latex')) print(mathgen.genById(71, style='latex'))