MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / surface_area_sphere

Function surface_area_sphere

maths/area.py:59–80  ·  view source on GitHub ↗

Calculate the Surface Area of a Sphere. Wikipedia reference: https://en.wikipedia.org/wiki/Sphere Formula: 4 * pi * r^2 >>> surface_area_sphere(5) 314.1592653589793 >>> surface_area_sphere(1) 12.566370614359172 >>> surface_area_sphere(1.6) 32.169908772

(radius: float)

Source from the content-addressed store, hash-verified

57
58
59def surface_area_sphere(radius: float) -> float:
60 """
61 Calculate the Surface Area of a Sphere.
62 Wikipedia reference: https://en.wikipedia.org/wiki/Sphere
63 Formula: 4 * pi * r^2
64
65 >>> surface_area_sphere(5)
66 314.1592653589793
67 >>> surface_area_sphere(1)
68 12.566370614359172
69 >>> surface_area_sphere(1.6)
70 32.169908772759484
71 >>> surface_area_sphere(0)
72 0.0
73 >>> surface_area_sphere(-1)
74 Traceback (most recent call last):
75 ...
76 ValueError: surface_area_sphere() only accepts non-negative values
77 """
78 if radius < 0:
79 raise ValueError("surface_area_sphere() only accepts non-negative values")
80 return 4 * pi * radius**2
81
82
83def surface_area_hemisphere(radius: float) -> float:

Callers 1

area.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected