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

Function area_square

maths/area.py:267–284  ·  view source on GitHub ↗

Calculate the area of a square. >>> area_square(10) 100 >>> area_square(0) 0 >>> area_square(1.6) 2.5600000000000005 >>> area_square(-1) Traceback (most recent call last): ... ValueError: area_square() only accepts non-negative values

(side_length: float)

Source from the content-addressed store, hash-verified

265
266
267def area_square(side_length: float) -> float:
268 """
269 Calculate the area of a square.
270
271 >>> area_square(10)
272 100
273 >>> area_square(0)
274 0
275 >>> area_square(1.6)
276 2.5600000000000005
277 >>> area_square(-1)
278 Traceback (most recent call last):
279 ...
280 ValueError: area_square() only accepts non-negative values
281 """
282 if side_length < 0:
283 raise ValueError("area_square() only accepts non-negative values")
284 return side_length**2
285
286
287def area_triangle(base: float, height: float) -> float:

Callers 1

area.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected