mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
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:
parent
b31ed8c494
commit
8a134e1f45
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user