mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-01-18 16:27:02 +00:00
Update area.py (#2524)
* Update area.py Added Area for Rhombhus * Update area.py Added rhombhus area. And fixed some gaps error. * Update area.py Added Rhombhus area. * Update area.py Fixed suggested changes
This commit is contained in:
parent
3b0169549e
commit
fb9b9ecccf
|
@ -186,6 +186,30 @@ def area_circle(radius: float) -> float:
|
|||
return pi * radius ** 2
|
||||
|
||||
|
||||
def area_rhombus(diagonal_1: float, diagonal_2: float) -> float:
|
||||
"""
|
||||
Calculate the area of a rhombus
|
||||
|
||||
>>> area_rhombus(10, 20)
|
||||
100.0
|
||||
>>> area_rhombus(-1, -2)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: area_rhombus() only accepts non-negative values
|
||||
>>> area_rhombus(1, -2)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: area_rhombus() only accepts non-negative values
|
||||
>>> area_rhombus(-1, 2)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: area_rhombus() only accepts non-negative values
|
||||
"""
|
||||
if diagonal_1 < 0 or diagonal_2 < 0:
|
||||
raise ValueError("area_rhombus() only accepts non-negative values")
|
||||
return 1 / 2 * diagonal_1 * diagonal_2
|
||||
|
||||
|
||||
def main():
|
||||
print("Areas of various geometric shapes: \n")
|
||||
print(f"Rectangle: {area_rectangle(10, 20)}")
|
||||
|
@ -197,6 +221,7 @@ def main():
|
|||
print("\nSurface Areas of various geometric shapes: \n")
|
||||
print(f"Cube: {surface_area_cube(20)}")
|
||||
print(f"Sphere: {surface_area_sphere(20)}")
|
||||
print(f"Rhombus: {area_rhombus(10, 20)}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Reference in New Issue
Block a user