From bac53548085b8fac4375ca93fb614f74489eaa5c Mon Sep 17 00:00:00 2001 From: Shiven Tripathi <58358532+ShivenTripathi@users.noreply.github.com> Date: Fri, 16 Oct 2020 23:56:22 +0530 Subject: [PATCH] add problem to find roots of quadratic equation --- mathgenerator/mathgen.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index 917fccc..90cd1ac 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -531,6 +531,15 @@ def commonFactorsFunc(maxVal=100): problem = f"Common Factors of {a} and {b} = " solution = arr return problem, solution + +def quadraticEquation(maxVal=100): + a = random.randint(1,maxVal) + c = random.randint(1,maxVal) + b = random.randint(4*a*c,4*maxVal*maxVal) + + problem = "Zeros of the Quadratic Equation {a}x^2+{b}x+{c}=0".format(a,b,c) + solution = str[(-b+sqrt(b^2-4*a*c))/2*a,(-b-sqrt(b^2-4*a*c))/2*a] + return problem,solution # || Class Instances #Format is: @@ -577,3 +586,4 @@ volumeCylinderGen = Generator("Volume of cylinder", 37, "Volume of cylinder with surfaceAreaConeGen = Generator("Surface Area of cone", 38, "Surface area of cone with height = a units and radius = b units is","c units^2", surfaceAreaCone) volumeConeGen = Generator("Volume of cone", 39, "Volume of cone with height = a units and radius = b units is","c units^3", volumeCone) commonFactors = Generator("Common Factors", 40, "Common Factors of {a} and {b} = ","[c, d, ...]",commonFactorsFunc) +quadraticEquationSolve = Generator("Quadratic Equation", 41, "Find the zeros {x1,x2} of the quadratic equation ax^2+bx+c=0", "x1,x2", quadraticEquation)