diff --git a/mathgenerator/funcs/basic_math/complex_division.py b/mathgenerator/funcs/basic_math/complex_division.py index 40a2f77..68504a0 100644 --- a/mathgenerator/funcs/basic_math/complex_division.py +++ b/mathgenerator/funcs/basic_math/complex_division.py @@ -1,14 +1,18 @@ from .__init__ import * -def complexDivisionFunc(maxRes=99, maxDivid=99): +def complexDivisionFunc(maxRes=99, maxDivid=99, style='raw'): a = random.randint(0, maxDivid) b = random.randint(1, min(maxRes, maxDivid)) c = a / b c = round(c, 2) - - problem = str(a) + "/" + str(b) + "=" - solution = str(c) + + if style == 'latex': + problem = "\\(" + str(a) + "\\div" + str(b) + "=\\)" + solution = "\\(" + str(c) + "\\)" + else: + problem = str(a) + "/" + str(b) + "=" + solution = str(c) return problem, solution diff --git a/mathgenerator/funcs/basic_math/divide_fractions.py b/mathgenerator/funcs/basic_math/divide_fractions.py index e9a9ec4..9fa5178 100644 --- a/mathgenerator/funcs/basic_math/divide_fractions.py +++ b/mathgenerator/funcs/basic_math/divide_fractions.py @@ -1,7 +1,7 @@ from .__init__ import * -def divideFractionsFunc(maxVal=10): +def divideFractionsFunc(maxVal=10, style='raw'): a = random.randint(1, maxVal) b = random.randint(1, maxVal) @@ -22,13 +22,22 @@ def divideFractionsFunc(maxVal=10): tmp_d = b * c gcd = calculate_gcd(tmp_n, tmp_d) - x = f"{tmp_n//gcd}/{tmp_d//gcd}" + sol_numerator = tmp_n//gcd + sol_denominator = tmp_d//gcd + x = f"{sol_numerator}/{sol_denominator}" if (tmp_d == 1 or tmp_d == gcd): - x = f"{tmp_n//gcd}" - # for equal numerator and denominators - problem = f"({a}/{b})/({c}/{d})" - solution = x + x = f"{sol_numerator}" + + if style == 'latex': + problem = "\\(\\frac{" + str(a) + "}{" + str(b) + "}\\div\\frac{" + str(c) + "}{" + str(d) + "}=\\)" + if tmp_d == 1 or tmp_d == gcd: + solution = "\\(" + str(sol_numerator) + "\\)" + else: + solution = "\\(\\frac{" + str(sol_numerator) + "}{" + str(sol_denominator) + "}\\)" + else: + problem = f"({a}/{b})/({c}/{d})" + solution = x return problem, solution diff --git a/mathgenerator/funcs/basic_math/division.py b/mathgenerator/funcs/basic_math/division.py index 7f53b63..df16f0a 100644 --- a/mathgenerator/funcs/basic_math/division.py +++ b/mathgenerator/funcs/basic_math/division.py @@ -1,15 +1,20 @@ from .__init__ import * -def divisionToIntFunc(maxA=25, maxB=25): +def divisionToIntFunc(maxA=25, maxB=25, style='raw'): a = random.randint(1, maxA) b = random.randint(1, maxB) divisor = a * b dividend = random.choice([a, b]) + quotient = divisor / dividend - problem = f"{divisor}/{dividend}=" - solution = int(divisor / dividend) + if style == 'latex': + problem = "\\(" + str(divisor) + "\\div" + str(dividend) + "=\\)" + solution = "\\(" + str(quotient) + "\\)" + else: + problem = f"{divisor}/{dividend}=" + solution = str(quotient) return problem, solution diff --git a/mathgenerator/funcs/basic_math/multiplication.py b/mathgenerator/funcs/basic_math/multiplication.py index 7e6e36e..ae1cb6f 100644 --- a/mathgenerator/funcs/basic_math/multiplication.py +++ b/mathgenerator/funcs/basic_math/multiplication.py @@ -1,7 +1,7 @@ from .__init__ import * -def multiplicationFunc(maxRes=99, maxMulti=99): +def multiplicationFunc(maxRes=99, maxMulti=99, style='raw'): a = random.randint(0, maxMulti) if a == 0: b = random.randint(0, maxRes) @@ -9,8 +9,12 @@ def multiplicationFunc(maxRes=99, maxMulti=99): b = random.randint(0, min(int(maxMulti / a), maxRes)) c = a * b - problem = str(a) + "*" + str(b) + "=" - solution = str(c) + if style == 'latex': + problem = "\\(" + str(a) + "\cdot" + str(b) + "=\\)" + solution = "\\(" + str(c) + "\\)" + else: + problem = str(a) + "*" + str(b) + "=" + solution = str(c) return problem, solution diff --git a/mathgenerator/funcs/basic_math/square.py b/mathgenerator/funcs/basic_math/square.py index 28ed2c3..7b0230e 100644 --- a/mathgenerator/funcs/basic_math/square.py +++ b/mathgenerator/funcs/basic_math/square.py @@ -1,12 +1,16 @@ from .__init__ import * -def squareFunc(maxSquareNum=20): +def squareFunc(maxSquareNum=20, style='raw'): a = random.randint(1, maxSquareNum) b = a * a - - problem = str(a) + "^2" + "=" - solution = str(b) + + if style == 'latex': + problem = "\\(" + str(a) + "^{2}=\\)" + solution = "\\(" + str(b) + "\\)" + else: + problem = str(a) + "^2" + "=" + solution = str(b) return problem, solution diff --git a/mathgenerator/funcs/basic_math/square_root.py b/mathgenerator/funcs/basic_math/square_root.py index fa09006..41019d8 100644 --- a/mathgenerator/funcs/basic_math/square_root.py +++ b/mathgenerator/funcs/basic_math/square_root.py @@ -1,12 +1,16 @@ from .__init__ import * -def squareRootFunc(minNo=1, maxNo=12): +def squareRootFunc(minNo=1, maxNo=12, style='raw'): b = random.randint(minNo, maxNo) a = b * b - problem = "sqrt(" + str(a) + ")=" - solution = str(b) + if style == 'latex': + problem = "\\(\\sqrt{" + str(a) + "}=\\)" + solution = "\\(" + str(b) + "\\)" + else: + problem = "sqrt(" + str(a) + ")=" + solution = str(b) return problem, solution