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:
Sabari Ganesh 2020-10-04 19:50:47 +05:30 committed by GitHub
parent 3b0169549e
commit fb9b9ecccf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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__":