From 8a134e1f45d05e21194e8fbb5763d5645b36088f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EA=B9=80=EC=88=98=EC=97=B0?= Date: Wed, 18 Nov 2020 19:35:51 +0900 Subject: [PATCH] update area.py (#3862) add method "area_ellipse" - Calculate the area of a ellipse Co-authored-by: 201502029 --- maths/area.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/maths/area.py b/maths/area.py index 393d45faa..24216e223 100644 --- a/maths/area.py +++ b/maths/area.py @@ -186,6 +186,32 @@ def area_circle(radius: float) -> float: return pi * radius ** 2 +def area_ellipse(radius_x: float, radius_y: float) -> float: + """ + Calculate the area of a ellipse + + >>> area_ellipse(10, 10) + 314.1592653589793 + >>> area_ellipse(10, 20) + 628.3185307179587 + >>> area_ellipse(-10, 20) + Traceback (most recent call last): + ... + ValueError: area_ellipse() only accepts non-negative values + >>> area_ellipse(10, -20) + Traceback (most recent call last): + ... + ValueError: area_ellipse() only accepts non-negative values + >>> area_ellipse(-10, -20) + Traceback (most recent call last): + ... + ValueError: area_ellipse() only accepts non-negative values + """ + if radius_x < 0 or radius_y < 0: + raise ValueError("area_ellipse() only accepts non-negative values") + return pi * radius_x * radius_y + + def area_rhombus(diagonal_1: float, diagonal_2: float) -> float: """ Calculate the area of a rhombus