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

Function surface_area_cylinder

maths/area.py:173–202  ·  view source on GitHub ↗

Calculate the Surface Area of a Cylinder. Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder Formula: 2 * pi * r * (h + r) >>> surface_area_cylinder(7, 10) 747.6990515543707 >>> surface_area_cylinder(1.6, 2.6) 42.22300526424682 >>> surface_area_cyl

(radius: float, height: float)

Source from the content-addressed store, hash-verified

171
172
173def surface_area_cylinder(radius: float, height: float) -> float:
174 """
175 Calculate the Surface Area of a Cylinder.
176 Wikipedia reference: https://en.wikipedia.org/wiki/Cylinder
177 Formula: 2 * pi * r * (h + r)
178
179 >>> surface_area_cylinder(7, 10)
180 747.6990515543707
181 >>> surface_area_cylinder(1.6, 2.6)
182 42.22300526424682
183 >>> surface_area_cylinder(0, 0)
184 0.0
185 >>> surface_area_cylinder(6, 8)
186 527.7875658030853
187 >>> surface_area_cylinder(-1, -2)
188 Traceback (most recent call last):
189 ...
190 ValueError: surface_area_cylinder() only accepts non-negative values
191 >>> surface_area_cylinder(1, -2)
192 Traceback (most recent call last):
193 ...
194 ValueError: surface_area_cylinder() only accepts non-negative values
195 >>> surface_area_cylinder(-1, 2)
196 Traceback (most recent call last):
197 ...
198 ValueError: surface_area_cylinder() only accepts non-negative values
199 """
200 if radius < 0 or height < 0:
201 raise ValueError("surface_area_cylinder() only accepts non-negative values")
202 return 2 * pi * radius * (height + radius)
203
204
205def surface_area_torus(torus_radius: float, tube_radius: float) -> float:

Callers 1

area.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected