diff --git a/maths/area.py b/maths/area.py index 0cbfd7957..393d45faa 100644 --- a/maths/area.py +++ b/maths/area.py @@ -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__":