Skip to content

Commit 1baee0f

Browse files
Suyeonkkk201502029
and
201502029
authored
update area.py (TheAlgorithms#3862)
add method "area_ellipse" - Calculate the area of a ellipse Co-authored-by: 201502029 <[email protected]>
1 parent c20a478 commit 1baee0f

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

Diff for: maths/area.py

+26
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,32 @@ def area_circle(radius: float) -> float:
186186
return pi * radius ** 2
187187

188188

189+
def area_ellipse(radius_x: float, radius_y: float) -> float:
190+
"""
191+
Calculate the area of a ellipse
192+
193+
>>> area_ellipse(10, 10)
194+
314.1592653589793
195+
>>> area_ellipse(10, 20)
196+
628.3185307179587
197+
>>> area_ellipse(-10, 20)
198+
Traceback (most recent call last):
199+
...
200+
ValueError: area_ellipse() only accepts non-negative values
201+
>>> area_ellipse(10, -20)
202+
Traceback (most recent call last):
203+
...
204+
ValueError: area_ellipse() only accepts non-negative values
205+
>>> area_ellipse(-10, -20)
206+
Traceback (most recent call last):
207+
...
208+
ValueError: area_ellipse() only accepts non-negative values
209+
"""
210+
if radius_x < 0 or radius_y < 0:
211+
raise ValueError("area_ellipse() only accepts non-negative values")
212+
return pi * radius_x * radius_y
213+
214+
189215
def area_rhombus(diagonal_1: float, diagonal_2: float) -> float:
190216
"""
191217
Calculate the area of a rhombus

0 commit comments

Comments
 (0)