update area.py (#3862)

add method "area_ellipse"
- Calculate the area of a ellipse

Co-authored-by: 201502029 <tnehd158@naver.com>
This commit is contained in:
김수연 2020-11-18 19:35:51 +09:00 committed by GitHub
parent b31ed8c494
commit 8a134e1f45
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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