Skip to content

Added surface area of cone #5178

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
wants to merge 1 commit into from
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
28 changes: 27 additions & 1 deletion maths/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ def surface_area_sphere(radius: float) -> float:
raise ValueError("surface_area_sphere() only accepts non-negative values")
return 4 * pi * radius ** 2

def surface_area_cone(radius: float, height: float) -> float:
"""
Calculate the Surface Area of a Cone.
Wikipedia reference: https://en.wikipedia.org/wiki/Cone
Formula: pi * r * [r + √(h**2 + r**2)]
>>> surface_area_cone(10, 24)
1130.973355292
>>> surface_area_cone(6, 8)
301.592894745
>>> area_cone(-1, -2)
Traceback (most recent call last):
...
ValueError: area_cone() only accepts non-negative values
>>> area_cone(1, -2)
Traceback (most recent call last):
...
ValueError: area_cone() only accepts non-negative values
>>> area_cone(-1, 2)
Traceback (most recent call last):
...
ValueError: area_cone() only accepts non-negative values
"""
if radius < 0:
raise ValueError("surface_area_cone() only accepts non-negative values")
return pi * r * [r + √(h**2 + r**2)]

def area_rectangle(length: float, width: float) -> float:
"""
Expand Down Expand Up @@ -281,8 +306,9 @@ def area_rhombus(diagonal_1: float, diagonal_2: float) -> float:
print(f"Triangle: {area_triangle_three_sides(5, 12, 13) = }")
print(f"Parallelogram: {area_parallelogram(10, 20) = }")
print(f"Trapezium: {area_trapezium(10, 20, 30) = }")
print(f"Rhombus: {area_rhombus(10, 20) = }")
print(f"Circle: {area_circle(20) = }")
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) = }")
print(f"Cone: {surface_area_cone(20, 20) = }")