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

Function vol_cuboid

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

Calculate the Volume of a Cuboid. :return: multiple of `width`, `length` and `height` >>> vol_cuboid(1, 1, 1) 1.0 >>> vol_cuboid(1, 2, 3) 6.0 >>> vol_cuboid(1.6, 2.6, 3.6) 14.976 >>> vol_cuboid(0, 0, 0) 0.0 >>> vol_cuboid(-1, 2, 3) Traceback (most r

(width: float, height: float, length: float)

Source from the content-addressed store, hash-verified

171
172
173def vol_cuboid(width: float, height: float, length: float) -> float:
174 """
175 Calculate the Volume of a Cuboid.
176
177 :return: multiple of `width`, `length` and `height`
178
179 >>> vol_cuboid(1, 1, 1)
180 1.0
181 >>> vol_cuboid(1, 2, 3)
182 6.0
183 >>> vol_cuboid(1.6, 2.6, 3.6)
184 14.976
185 >>> vol_cuboid(0, 0, 0)
186 0.0
187 >>> vol_cuboid(-1, 2, 3)
188 Traceback (most recent call last):
189 ...
190 ValueError: vol_cuboid() only accepts non-negative values
191 >>> vol_cuboid(1, -2, 3)
192 Traceback (most recent call last):
193 ...
194 ValueError: vol_cuboid() only accepts non-negative values
195 >>> vol_cuboid(1, 2, -3)
196 Traceback (most recent call last):
197 ...
198 ValueError: vol_cuboid() only accepts non-negative values
199 """
200 if width < 0 or height < 0 or length < 0:
201 raise ValueError("vol_cuboid() only accepts non-negative values")
202 return float(width * height * length)
203
204
205def vol_cone(area_of_base: float, height: float) -> float:

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected