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

View File

@@ -1,7 +1,7 @@
from .__init__ import *
def compareFractionsFunc(maxVal=10):
def compareFractionsFunc(maxVal=10, style='raw'):
a = random.randint(1, maxVal)
b = random.randint(1, maxVal)
c = random.randint(1, maxVal)
@@ -21,8 +21,11 @@ def compareFractionsFunc(maxVal=10):
solution = "<"
else:
solution = "="
problem = f"Which symbol represents the comparison between {a}/{b} and {c}/{d}?"
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}?"
return problem, solution

View File

@@ -1,12 +1,16 @@
from .__init__ import *
def cubeRootFunc(minNo=1, maxNo=1000):
def cubeRootFunc(minNo=1, maxNo=1000, style='raw'):
b = random.randint(minNo, maxNo)
a = b**(1 / 3)
problem = "cuberoot of " + str(b) + " upto 2 decimal places is:"
solution = str(round(a, 2))
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))
return problem, solution

View File

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

View File

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

View File

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

View File

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