diff --git a/mathgenerator/funcs/basic_math/absolute_difference.py b/mathgenerator/funcs/basic_math/absolute_difference.py index fae1fb0..bb5f662 100644 --- a/mathgenerator/funcs/basic_math/absolute_difference.py +++ b/mathgenerator/funcs/basic_math/absolute_difference.py @@ -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 diff --git a/mathgenerator/funcs/basic_math/compare_fractions.py b/mathgenerator/funcs/basic_math/compare_fractions.py index 53fe7a0..851e0ec 100644 --- a/mathgenerator/funcs/basic_math/compare_fractions.py +++ b/mathgenerator/funcs/basic_math/compare_fractions.py @@ -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 diff --git a/mathgenerator/funcs/basic_math/cube_root.py b/mathgenerator/funcs/basic_math/cube_root.py index 06a6a8d..736fb90 100644 --- a/mathgenerator/funcs/basic_math/cube_root.py +++ b/mathgenerator/funcs/basic_math/cube_root.py @@ -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 diff --git a/mathgenerator/funcs/basic_math/exponentiation.py b/mathgenerator/funcs/basic_math/exponentiation.py index dd764e4..b4fa8ad 100644 --- a/mathgenerator/funcs/basic_math/exponentiation.py +++ b/mathgenerator/funcs/basic_math/exponentiation.py @@ -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 diff --git a/mathgenerator/funcs/basic_math/is_prime.py b/mathgenerator/funcs/basic_math/is_prime.py index ac3ede5..07981de 100644 --- a/mathgenerator/funcs/basic_math/is_prime.py +++ b/mathgenerator/funcs/basic_math/is_prime.py @@ -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) diff --git a/mathgenerator/funcs/basic_math/percentage.py b/mathgenerator/funcs/basic_math/percentage.py index e108a10..64d3d98 100644 --- a/mathgenerator/funcs/basic_math/percentage.py +++ b/mathgenerator/funcs/basic_math/percentage.py @@ -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 diff --git a/mathgenerator/funcs/basic_math/power_of_powers.py b/mathgenerator/funcs/basic_math/power_of_powers.py index 6aae3ae..714107a 100644 --- a/mathgenerator/funcs/basic_math/power_of_powers.py +++ b/mathgenerator/funcs/basic_math/power_of_powers.py @@ -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 diff --git a/test.py b/test.py index 1998f11..43d0e50 100644 --- a/test.py +++ b/test.py @@ -1,4 +1,4 @@ from mathgenerator import mathgen for _ in range(100): - print(mathgen.genById(28, style='latex')) + print(mathgen.genById(71, style='latex'))