mirror of
https://github.com/DeaDvey/mathgenerator.git
synced 2025-11-28 06:25:23 +01:00
added latex to 2, 3, 6, 8, 13, 16
This commit is contained in:
@@ -1,12 +1,16 @@
|
||||
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)
|
||||
|
||||
if style == 'latex':
|
||||
problem = "\\(" + str(a) + "\\div" + str(b) + "=\\)"
|
||||
solution = "\\(" + str(c) + "\\)"
|
||||
else:
|
||||
problem = str(a) + "/" + str(b) + "="
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
|
||||
@@ -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,11 +22,20 @@ 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
|
||||
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
|
||||
|
||||
@@ -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
|
||||
|
||||
if style == 'latex':
|
||||
problem = "\\(" + str(divisor) + "\\div" + str(dividend) + "=\\)"
|
||||
solution = "\\(" + str(quotient) + "\\)"
|
||||
else:
|
||||
problem = f"{divisor}/{dividend}="
|
||||
solution = int(divisor / dividend)
|
||||
solution = str(quotient)
|
||||
return problem, solution
|
||||
|
||||
|
||||
|
||||
@@ -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,6 +9,10 @@ def multiplicationFunc(maxRes=99, maxMulti=99):
|
||||
b = random.randint(0, min(int(maxMulti / a), maxRes))
|
||||
c = a * b
|
||||
|
||||
if style == 'latex':
|
||||
problem = "\\(" + str(a) + "\cdot" + str(b) + "=\\)"
|
||||
solution = "\\(" + str(c) + "\\)"
|
||||
else:
|
||||
problem = str(a) + "*" + str(b) + "="
|
||||
solution = str(c)
|
||||
return problem, solution
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
from .__init__ import *
|
||||
|
||||
|
||||
def squareFunc(maxSquareNum=20):
|
||||
def squareFunc(maxSquareNum=20, style='raw'):
|
||||
a = random.randint(1, maxSquareNum)
|
||||
b = a * a
|
||||
|
||||
if style == 'latex':
|
||||
problem = "\\(" + str(a) + "^{2}=\\)"
|
||||
solution = "\\(" + str(b) + "\\)"
|
||||
else:
|
||||
problem = str(a) + "^2" + "="
|
||||
solution = str(b)
|
||||
return problem, solution
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
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
|
||||
|
||||
if style == 'latex':
|
||||
problem = "\\(\\sqrt{" + str(a) + "}=\\)"
|
||||
solution = "\\(" + str(b) + "\\)"
|
||||
else:
|
||||
problem = "sqrt(" + str(a) + ")="
|
||||
solution = str(b)
|
||||
return problem, solution
|
||||
|
||||
Reference in New Issue
Block a user