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

Function vol_cone

maths/volume.py:205–231  ·  view source on GitHub ↗

r""" | Calculate the Volume of a Cone. | Wikipedia reference: https://en.wikipedia.org/wiki/Cone :return: :math:`\frac{1}{3} \cdot area\_of\_base \cdot height` >>> vol_cone(10, 3) 10.0 >>> vol_cone(1, 1) 0.3333333333333333 >>> vol_cone(1.6, 1.6) 0.85333333333333

(area_of_base: float, height: float)

Source from the content-addressed store, hash-verified

203
204
205def vol_cone(area_of_base: float, height: float) -> float:
206 r"""
207 | Calculate the Volume of a Cone.
208 | Wikipedia reference: https://en.wikipedia.org/wiki/Cone
209
210 :return: :math:`\frac{1}{3} \cdot area\_of\_base \cdot height`
211
212 >>> vol_cone(10, 3)
213 10.0
214 >>> vol_cone(1, 1)
215 0.3333333333333333
216 >>> vol_cone(1.6, 1.6)
217 0.8533333333333335
218 >>> vol_cone(0, 0)
219 0.0
220 >>> vol_cone(-1, 1)
221 Traceback (most recent call last):
222 ...
223 ValueError: vol_cone() only accepts non-negative values
224 >>> vol_cone(1, -1)
225 Traceback (most recent call last):
226 ...
227 ValueError: vol_cone() only accepts non-negative values
228 """
229 if height < 0 or area_of_base < 0:
230 raise ValueError("vol_cone() only accepts non-negative values")
231 return area_of_base * height / 3.0
232
233
234def vol_right_circ_cone(radius: float, height: float) -> float:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected