Skip to content

added simplifying comments #6502

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions maths/area.py
Original file line number Diff line number Diff line change
@@ -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.
>>> surface_area_cube(1)
@@ -22,7 +23,8 @@ 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_cuboid(length: float, breadth: float, height: float) -> float:
@@ -72,7 +74,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:
@@ -299,11 +301,16 @@ 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)
@@ -343,6 +350,12 @@ def area_parallelogram(base: float, height: float) -> float:
def area_trapezium(base1: float, base2: float, height: float) -> float:
"""
Calculate the area of a trapezium.
<<<<<<< patch-2
Formula - (a+b) * height * 0.5
a = parallele side 1, b = parallel side 2
=======
>>>>>>> master
>>> area_trapezium(10, 20, 30)
450.0
>>> area_trapezium(1.6, 2.6, 3.6)
@@ -378,6 +391,8 @@ 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")
return 1 / 2 * (base1 + base2) * height
@@ -434,6 +449,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
>>> area_rhombus(1.6, 2.6)