From bb74ff3a398d1805f51db6bf2da1da9fb3aee25a Mon Sep 17 00:00:00 2001 From: Advik Sharma <70201060+advik-student-dev@users.noreply.github.com> Date: Sat, 1 Oct 2022 17:16:38 -0700 Subject: [PATCH 1/7] added simplifying comments added some comments to make the code reader able to visualise the equations (i.e write the equations in an algebraic manner so that another programmer will know the exact equation). not added comments like this to all of the calcs --- maths/area.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/maths/area.py b/maths/area.py index b1b139cf4e22..7b0adbf5f9fe 100644 --- a/maths/area.py +++ b/maths/area.py @@ -5,6 +5,7 @@ def surface_area_cube(side_length: float) -> float: + # Exact Formula - side_length^2 * 6 """ Calculate the Surface Area of a Cube. @@ -19,7 +20,7 @@ def surface_area_cube(side_length: float) -> float: """ if side_length < 0: raise ValueError("surface_area_cube() only accepts non-negative values") - return 6 * side_length**2 + return 6 * side_length**2 # Side length is squared to get the area of 1 side which is then multiplied by 6 because a cube has 6 sides def surface_area_sphere(radius: float) -> float: @@ -39,7 +40,7 @@ def surface_area_sphere(radius: float) -> float: """ if radius < 0: raise ValueError("surface_area_sphere() only accepts non-negative values") - return 4 * pi * radius**2 + return 4 * pi * radius**2 # radius**2 = r^2 def surface_area_hemisphere(radius: float) -> float: @@ -216,11 +217,14 @@ def area_triangle_three_sides(side1: float, side2: float, side3: float) -> float ... ValueError: Given three sides do not form a triangle """ + + # Area = √(s(s-a)(s-b)(s-c)) - Mathematical notation of Heron's Formula + if side1 < 0 or side2 < 0 or side3 < 0: raise ValueError("area_triangle_three_sides() only accepts non-negative values") - elif side1 + side2 < side3 or side1 + side3 < side2 or side2 + side3 < side1: + elif side1 + side2 < side3 or side1 + side3 < side2 or side2 + side3 < side1: # Sum of 2 sides must be higher than 1 side - Math Axiom raise ValueError("Given three sides do not form a triangle") - semi_perimeter = (side1 + side2 + side3) / 2 + semi_perimeter = (side1 + side2 + side3) / 2 # Math semi-perimeter formula area = sqrt( semi_perimeter * (semi_perimeter - side1) @@ -289,6 +293,8 @@ def area_trapezium(base1: float, base2: float, height: float) -> float: ... ValueError: area_trapezium() only accepts non-negative values """ + + # Area = (parellel side 1 + parellel side 2) * height / 2 if base1 < 0 or base2 < 0 or height < 0: raise ValueError("area_trapezium() only accepts non-negative values") return 1 / 2 * (base1 + base2) * height From 4a639bba7748f8d3d4f71081e5b986e2aaac18af Mon Sep 17 00:00:00 2001 From: Advik Sharma <70201060+advik-student-dev@users.noreply.github.com> Date: Sun, 2 Oct 2022 15:22:04 -0700 Subject: [PATCH 2/7] Update maths/area.py Co-authored-by: Caeden --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 7b0adbf5f9fe..d3435fa6d60d 100644 --- a/maths/area.py +++ b/maths/area.py @@ -294,7 +294,7 @@ def area_trapezium(base1: float, base2: float, height: float) -> float: ValueError: area_trapezium() only accepts non-negative values """ - # Area = (parellel side 1 + parellel side 2) * height / 2 + # Area = (parallel side 1 + parallel side 2) * height / 2 if base1 < 0 or base2 < 0 or height < 0: raise ValueError("area_trapezium() only accepts non-negative values") return 1 / 2 * (base1 + base2) * height From bd3e470a8a3d5b92fabddeb1c368c3e7cb0fc103 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Oct 2022 22:22:51 +0000 Subject: [PATCH 3/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/area.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/maths/area.py b/maths/area.py index d3435fa6d60d..b57ed56ace54 100644 --- a/maths/area.py +++ b/maths/area.py @@ -20,7 +20,9 @@ def surface_area_cube(side_length: float) -> float: """ if side_length < 0: raise ValueError("surface_area_cube() only accepts non-negative values") - return 6 * side_length**2 # Side length is squared to get the area of 1 side which is then multiplied by 6 because a cube has 6 sides + return ( + 6 * side_length**2 + ) # Side length is squared to get the area of 1 side which is then multiplied by 6 because a cube has 6 sides def surface_area_sphere(radius: float) -> float: @@ -217,12 +219,14 @@ def area_triangle_three_sides(side1: float, side2: float, side3: float) -> float ... ValueError: Given three sides do not form a triangle """ - + # Area = √(s(s-a)(s-b)(s-c)) - Mathematical notation of Heron's Formula - + if side1 < 0 or side2 < 0 or side3 < 0: raise ValueError("area_triangle_three_sides() only accepts non-negative values") - elif side1 + side2 < side3 or side1 + side3 < side2 or side2 + side3 < side1: # Sum of 2 sides must be higher than 1 side - Math Axiom + elif ( + side1 + side2 < side3 or side1 + side3 < side2 or side2 + side3 < side1 + ): # Sum of 2 sides must be higher than 1 side - Math Axiom raise ValueError("Given three sides do not form a triangle") semi_perimeter = (side1 + side2 + side3) / 2 # Math semi-perimeter formula area = sqrt( @@ -293,7 +297,7 @@ def area_trapezium(base1: float, base2: float, height: float) -> float: ... ValueError: area_trapezium() only accepts non-negative values """ - + # Area = (parallel side 1 + parallel side 2) * height / 2 if base1 < 0 or base2 < 0 or height < 0: raise ValueError("area_trapezium() only accepts non-negative values") From 277287a1af74f6959360608298dd78747a2abf4e Mon Sep 17 00:00:00 2001 From: Advik Sharma <70201060+advik-student-dev@users.noreply.github.com> Date: Sun, 2 Oct 2022 15:34:40 -0700 Subject: [PATCH 4/7] Update area.py --- maths/area.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index b57ed56ace54..479fe29202c6 100644 --- a/maths/area.py +++ b/maths/area.py @@ -22,7 +22,8 @@ def surface_area_cube(side_length: float) -> float: raise ValueError("surface_area_cube() only accepts non-negative values") return ( 6 * side_length**2 - ) # Side length is squared to get the area of 1 side which is then multiplied by 6 because a cube has 6 sides + ) # Side length is squared to get the area of 1 side \ + # which is then multiplied by 6 because a cube has 6 sides def surface_area_sphere(radius: float) -> float: From a54b4d229e9851a4960cc025972488ed450bd945 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 2 Oct 2022 22:35:29 +0000 Subject: [PATCH 5/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/area.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/maths/area.py b/maths/area.py index 479fe29202c6..444cc43bc0c9 100644 --- a/maths/area.py +++ b/maths/area.py @@ -20,9 +20,7 @@ def surface_area_cube(side_length: float) -> float: """ if side_length < 0: raise ValueError("surface_area_cube() only accepts non-negative values") - return ( - 6 * side_length**2 - ) # Side length is squared to get the area of 1 side \ + return 6 * side_length**2 # Side length is squared to get the area of 1 side \ # which is then multiplied by 6 because a cube has 6 sides From 62975512a717dd0c4a3157a9bdee17a161f8381a Mon Sep 17 00:00:00 2001 From: Advik Sharma <70201060+advik-student-dev@users.noreply.github.com> Date: Wed, 12 Oct 2022 19:56:14 -0700 Subject: [PATCH 6/7] Update area.py --- maths/area.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/maths/area.py b/maths/area.py index 444cc43bc0c9..918506aa0c9d 100644 --- a/maths/area.py +++ b/maths/area.py @@ -264,6 +264,8 @@ def area_parallelogram(base: float, height: float) -> float: def area_trapezium(base1: float, base2: float, height: float) -> float: """ Calculate the area of a trapezium. + Formula - (a+b) * height * 0.5 + a = parallele side 1, b = parallel side 2 >>> area_trapezium(10, 20, 30) 450.0 @@ -348,6 +350,7 @@ def area_ellipse(radius_x: float, radius_y: float) -> float: def area_rhombus(diagonal_1: float, diagonal_2: float) -> float: """ Calculate the area of a rhombus. + Formula - (diagonal 1 * diagonal 2)/2 >>> area_rhombus(10, 20) 100.0 From bddc04e1114f64a05d6dcf7e117514ca79771f26 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Fri, 14 Oct 2022 20:39:24 +0000 Subject: [PATCH 7/7] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- maths/area.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/area.py b/maths/area.py index 9f716a23dbe4..11042a30d2ca 100644 --- a/maths/area.py +++ b/maths/area.py @@ -351,7 +351,7 @@ def area_trapezium(base1: float, base2: float, height: float) -> float: """ Calculate the area of a trapezium. <<<<<<< patch-2 - Formula - (a+b) * height * 0.5 + Formula - (a+b) * height * 0.5 a = parallele side 1, b = parallel side 2 =======