From 49d83c966de79f3f7b08a62f2a845b94dc938aed Mon Sep 17 00:00:00 2001 From: jsun1590 Date: Sat, 9 Oct 2021 20:14:12 +0800 Subject: [PATCH] made c dependent on a and b Removed maxC as we had to make c dependent on a and b. Also wrapped a round function around the solution to 2 decimal places. --- mathgenerator/funcs/geometry/area_of_triangle.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/mathgenerator/funcs/geometry/area_of_triangle.py b/mathgenerator/funcs/geometry/area_of_triangle.py index a60f39a..4be8824 100644 --- a/mathgenerator/funcs/geometry/area_of_triangle.py +++ b/mathgenerator/funcs/geometry/area_of_triangle.py @@ -1,10 +1,10 @@ from .__init__ import * -def gen_func(maxA=20, maxB=20, maxC=20, format='string'): +def gen_func(maxA=20, maxB=20, format='string'): a = random.randint(1, maxA) b = random.randint(1, maxB) - c = random.randint(1, maxC) + c = random.randint(abs(b-a)+1, abs(a+b)-1) s = (a + b + c) / 2 area = (s * (s - a) * (s - b) * (s - c))**0.5 @@ -12,7 +12,7 @@ def gen_func(maxA=20, maxB=20, maxC=20, format='string'): if format == 'string': problem = "Area of triangle with side lengths: " + \ str(a) + " " + str(b) + " " + str(c) + " = " - solution = str(area) + solution = str(round(area, 2)) return problem, solution elif format == 'latex': return "Latex unavailable" @@ -21,4 +21,4 @@ def gen_func(maxA=20, maxB=20, maxC=20, format='string'): area_of_triangle = Generator("Area of Triangle", 18, gen_func, - ["maxA=20", "maxB=20", "maxC=20"]) + ["maxA=20", "maxB=20"])