From d2830507cfdeb209aa1848f88b98c11a6e90c726 Mon Sep 17 00:00:00 2001 From: Aditya Mahimkar Date: Thu, 15 Oct 2020 23:38:32 +0530 Subject: [PATCH 1/2] Update mathgen.py --- mathgenerator/mathgen.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index a7063b2..54943b1 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -206,6 +206,16 @@ def divideFractionsFunc(maxVal=10): solution = x return problem, solution +def areaOfTriangleFunc(maxA=20, maxB=20, maxC=20): + a = random.randint(1, maxA) + b = random.randint(1, maxB) + c = random.randint(1, maxC) + s = (a+b+c)/2 + area = (s*(s-a)*(s-b)*(s-c)) ** 0.5 + problem = "Area of triangle with side lengths: "+ str(a) +" "+ str(b) +" "+ str(c) " = " + solution = area + return problem, solution + # || Class Instances #Format is: @@ -227,3 +237,4 @@ intDivision = Generator("Easy Division", 13,"a/b=","c",divisionToIntFunc) decimalToBinary = Generator("Decimal to Binary",14,"Binary of a=","b",DecimalToBinaryFunc) binaryToDecimal = Generator("Binary to Decimal",15,"Decimal of a=","b",BinaryToDecimalFunc) fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc) +areaOfTriangle = Generator("Area of Triangle", 18, "Area of Triangle with side lengths a, b, c = ", "area", areaOfTriangleFunc) From 734dd662c5af557a86f9de4b2cfbdf375af8e2ee Mon Sep 17 00:00:00 2001 From: ieshaan12 Date: Thu, 15 Oct 2020 23:57:19 +0530 Subject: [PATCH 2/2] Triangle exists check --- mathgenerator/mathgen.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/mathgenerator/mathgen.py b/mathgenerator/mathgen.py index e9987ad..c962df1 100644 --- a/mathgenerator/mathgen.py +++ b/mathgenerator/mathgen.py @@ -216,6 +216,19 @@ def multiplyIntToMatrix22(maxMatrixVal = 10, maxRes = 100): solution = f"[[{a*constant},{b*constant}],[{c*constant},{d*constant}]]" return problem, solution +def isTriangleValid(maxSideLength = 50): + sideA = random.randint(1, maxSideLength) + sideB = random.randint(1, maxSideLength) + sideC = random.randint(1, maxSideLength) + sideSums = [sideA + sideB, sideB + sideC, sideC + sideA] + sides = [sideC, sideA, sideB] + exists = True & (sides[0] < sideSums[0]) & (sides[1] < sideSums[1]) & (sides[2] < sideSums[2]) + problem = f"Does triangle with sides {sideA}, {sideB} and {sideC} exist?" + if exists: + solution = "Yes" + return problem, solution + solution = "No" + return problem, solution # || Class Instances @@ -238,4 +251,5 @@ intDivision = Generator("Easy Division", 13,"a/b=","c",divisionToIntFunc) decimalToBinary = Generator("Decimal to Binary",14,"Binary of a=","b",DecimalToBinaryFunc) binaryToDecimal = Generator("Binary to Decimal",15,"Decimal of a=","b",BinaryToDecimalFunc) fractionDivision = Generator("Fraction Division", 16, "(a/b)/(c/d)=", "x/y", divideFractionsFunc) -intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22) \ No newline at end of file +intMatrix22Multiplication = Generator("Integer Multiplication with 2x2 Matrix", 17, "k * [[a,b],[c,d]]=", "[[k*a,k*b],[k*c,k*d]]", multiplyIntToMatrix22) +doesTriangleExist = Generator("Triangle exists check", 18, "Does triangle with sides a, b and c exist?","Yes/No", isTriangleValid)