Skip to content

Commit 5fe834f

Browse files
SabariGanesh-Kstokhos
authored andcommitted
Update area.py (TheAlgorithms#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
1 parent a0612bb commit 5fe834f

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Diff for: maths/area.py

+25
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,30 @@ def area_circle(radius: float) -> float:
186186
return pi * radius ** 2
187187

188188

189+
def area_rhombus(diagonal_1: float, diagonal_2: float) -> float:
190+
"""
191+
Calculate the area of a rhombus
192+
193+
>>> area_rhombus(10, 20)
194+
100.0
195+
>>> area_rhombus(-1, -2)
196+
Traceback (most recent call last):
197+
...
198+
ValueError: area_rhombus() only accepts non-negative values
199+
>>> area_rhombus(1, -2)
200+
Traceback (most recent call last):
201+
...
202+
ValueError: area_rhombus() only accepts non-negative values
203+
>>> area_rhombus(-1, 2)
204+
Traceback (most recent call last):
205+
...
206+
ValueError: area_rhombus() only accepts non-negative values
207+
"""
208+
if diagonal_1 < 0 or diagonal_2 < 0:
209+
raise ValueError("area_rhombus() only accepts non-negative values")
210+
return 1 / 2 * diagonal_1 * diagonal_2
211+
212+
189213
def main():
190214
print("Areas of various geometric shapes: \n")
191215
print(f"Rectangle: {area_rectangle(10, 20)}")
@@ -197,6 +221,7 @@ def main():
197221
print("\nSurface Areas of various geometric shapes: \n")
198222
print(f"Cube: {surface_area_cube(20)}")
199223
print(f"Sphere: {surface_area_sphere(20)}")
224+
print(f"Rhombus: {area_rhombus(10, 20)}")
200225

201226

202227
if __name__ == "__main__":

0 commit comments

Comments
 (0)