diff --git a/mathgenerator/funcs/__init__.py b/mathgenerator/funcs/__init__.py index b8fc5a5..7f48dcc 100644 --- a/mathgenerator/funcs/__init__.py +++ b/mathgenerator/funcs/__init__.py @@ -115,3 +115,4 @@ from .conditional_probability import * from .arc_length import * from .binomial_distribution import * from .stationary_points import * +from .expanding import * diff --git a/mathgenerator/funcs/expanding.py b/mathgenerator/funcs/expanding.py new file mode 100644 index 0000000..b9d804e --- /dev/null +++ b/mathgenerator/funcs/expanding.py @@ -0,0 +1,48 @@ +from .__init__ import * + + +def expandingFunc(range_x1=10, range_x2=10, range_a=10, range_b=10): + x1 = random.randint(-range_x1, range_x1) + x2 = random.randint(-range_x2, range_x2) + a = random.randint(-range_a, range_a) + b = random.randint(-range_b, range_b) + + def intParser(z): + if (z == 0): + return "" + if (z > 0): + return "+" + str(z) + if (z < 0): + return "-" + str(abs(z)) + + c1 = intParser(a * b) + c2 = intParser((a*x2)+(b*x1)) + c3 = intParser(x1 * x2) + + p1 = intParser(a) + p2 = intParser(x1) + p3 = intParser(b) + p4 = intParser(x2) + + if p1 == "+1": + p1 = "" + if p1[0] == "+": + p1 = p1[1:] + if p3 == "+1": + p3 = "" + if p3 == "+": + p3 = p3[1:] + problem = f"({p1}x{p2})({p3}x{p4})" + + if c1 == "+1": + c1 = "" + if c1[0] == "+": + c1 = c1[1:] # Cuts off the plus for readability + if c2 == "+1": + c2 = "" + solution = f"{c1}*x^2{c2}*x{c3}" + return problem, solution + + +expanding = Generator("Expanding Factored Binomial", 111, "(a*x-x1)(b*x-x2)", + "a*b*x^2+(b*x1+a*x2)*x+x1*x2", expandingFunc) diff --git a/test.py b/test.py index 3eeff53..7432e8a 100644 --- a/test.py +++ b/test.py @@ -10,4 +10,4 @@ for item in list: print(item[2]) # print(mathgen.getGenList()) -print(mathgen.genById(110)) +print(mathgen.genById(111))