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

Function perfect_cube

maths/perfect_cube.py:1–11  ·  view source on GitHub ↗

Check if a number is a perfect cube or not. >>> perfect_cube(27) True >>> perfect_cube(4) False

(n: int)

Source from the content-addressed store, hash-verified

1def perfect_cube(n: int) -> bool:
2 """
3 Check if a number is a perfect cube or not.
4
5 >>> perfect_cube(27)
6 True
7 >>> perfect_cube(4)
8 False
9 """
10 val = n ** (1 / 3)
11 return (val * val * val) == n
12
13
14def perfect_cube_binary_search(n: int) -> bool:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected