From c0c66222787111db9fb63955c0fecabe619e49ae Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Wed, 30 Sep 2020 21:44:10 +0530 Subject: [PATCH 1/4] Update area.py Added Area for Rhombhus --- maths/area.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 0cbfd7957fa6..9b212fadef33 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_rhombhus(base: float, height: float) -> float: + """ + Calculate the area of a rhombhus + + >>> area_rhombhus(10, 20) + 100.0 + >>> area_rhombhus(-1, -2) + Traceback (most recent call last): + ... + ValueError: area_rhombhus() only accepts non-negative values + >>> area_rhombhus(1, -2) + Traceback (most recent call last): + ... + ValueError: area_rhombhus() only accepts non-negative values + >>> area_rhombhus(-1, 2) + Traceback (most recent call last): + ... + ValueError: area_rhombhus() only accepts non-negative values + """ + if base < 0 or height < 0: + raise ValueError("area_rhombhus() only accepts non-negative values") + return 1/2 * base * height + + def main(): print("Areas of various geometric shapes: \n") print(f"Rectangle: {area_rectangle(10, 20)}") @@ -197,7 +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"Rhombhus: {area_rhombhus(10, 20)}") if __name__ == "__main__": From d35ce93834bf7ef8df8ed14e3de73843096f6666 Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Wed, 30 Sep 2020 21:57:55 +0530 Subject: [PATCH 2/4] Update area.py Added rhombhus area. And fixed some gaps error. --- maths/area.py | 1 + 1 file changed, 1 insertion(+) diff --git a/maths/area.py b/maths/area.py index 9b212fadef33..5b875782c0a6 100644 --- a/maths/area.py +++ b/maths/area.py @@ -223,6 +223,7 @@ def main(): print(f"Sphere: {surface_area_sphere(20)}") print(f"Rhombhus: {area_rhombhus(10, 20)}") + if __name__ == "__main__": import doctest From af6f55bf6f870368436ea8fe678438af06c5f650 Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Wed, 30 Sep 2020 22:06:15 +0530 Subject: [PATCH 3/4] Update area.py Added Rhombhus area. --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 5b875782c0a6..ae7ab5870613 100644 --- a/maths/area.py +++ b/maths/area.py @@ -207,7 +207,7 @@ def area_rhombhus(base: float, height: float) -> float: """ if base < 0 or height < 0: raise ValueError("area_rhombhus() only accepts non-negative values") - return 1/2 * base * height + return 1 / 2 * base * height def main(): From 56c0bfe0786f8810ad57702f1a6ffca0de5fa6d1 Mon Sep 17 00:00:00 2001 From: Sabari Ganesh <64348740+SabariGanesh-K@users.noreply.github.com> Date: Sun, 4 Oct 2020 09:15:32 +0530 Subject: [PATCH 4/4] Update area.py Fixed suggested changes --- maths/area.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/maths/area.py b/maths/area.py index ae7ab5870613..393d45faa880 100644 --- a/maths/area.py +++ b/maths/area.py @@ -186,28 +186,28 @@ def area_circle(radius: float) -> float: return pi * radius ** 2 -def area_rhombhus(base: float, height: float) -> float: +def area_rhombus(diagonal_1: float, diagonal_2: float) -> float: """ - Calculate the area of a rhombhus + Calculate the area of a rhombus - >>> area_rhombhus(10, 20) + >>> area_rhombus(10, 20) 100.0 - >>> area_rhombhus(-1, -2) + >>> area_rhombus(-1, -2) Traceback (most recent call last): ... - ValueError: area_rhombhus() only accepts non-negative values - >>> area_rhombhus(1, -2) + ValueError: area_rhombus() only accepts non-negative values + >>> area_rhombus(1, -2) Traceback (most recent call last): ... - ValueError: area_rhombhus() only accepts non-negative values - >>> area_rhombhus(-1, 2) + ValueError: area_rhombus() only accepts non-negative values + >>> area_rhombus(-1, 2) Traceback (most recent call last): ... - ValueError: area_rhombhus() only accepts non-negative values + ValueError: area_rhombus() only accepts non-negative values """ - if base < 0 or height < 0: - raise ValueError("area_rhombhus() only accepts non-negative values") - return 1 / 2 * base * height + 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(): @@ -221,7 +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"Rhombhus: {area_rhombhus(10, 20)}") + print(f"Rhombus: {area_rhombus(10, 20)}") if __name__ == "__main__":