From 4212e23adad713bcffec320e9b3dcaf85b676d8d Mon Sep 17 00:00:00 2001 From: Nic Bestauros <54752907+nBestauros@users.noreply.github.com> Date: Fri, 2 Jun 2023 07:21:40 -0700 Subject: [PATCH] Add Area Of Trapezoid (#419) * Added area_of_trapezoid. * Fixed spacing in file. * Move area of trapezoid to latest gen_list --------- Co-authored-by: Luke Weiler --- mathgenerator/_gen_list.py | 1 + mathgenerator/geometry.py | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/mathgenerator/_gen_list.py b/mathgenerator/_gen_list.py index 8d2b18a..4cca868 100644 --- a/mathgenerator/_gen_list.py +++ b/mathgenerator/_gen_list.py @@ -128,4 +128,5 @@ gen_list = [ ("simplify_square_root", "basic_math"), ("line_equation_from_2_points", "algebra"), ("orthogonal_projection", "algebra"), + ("area_of_trapezoid", "geometry"), ] diff --git a/mathgenerator/geometry.py b/mathgenerator/geometry.py index a68dd32..ad8c6ee 100644 --- a/mathgenerator/geometry.py +++ b/mathgenerator/geometry.py @@ -104,6 +104,24 @@ def area_of_circle_given_center_and_point(max_coordinate=10, max_radius=10): return problem, f'${area}$' +def area_of_trapezoid(max_len=20): + r"""Area of Trapezoid + + | Ex. Problem | Ex. Solution | + | --- | --- | + | Area of trapezoid with height $12$ and base lengths: $3, 7, = $ | $60$ | + """ + a = random.randint(1, max_len) + b = random.randint(1, max_len) + h = random.randint(1, max_len) + + area = (a + b) * h / 2 + + problem = f"Area of trapezoid with height ${h}$ and base lengths: ${a}, {b}, = $" + solution = f'${round(area, 2)}$' + return problem, solution + + def area_of_triangle(max_a=20, max_b=20): r"""Area of Triangle