mirror of
https://hub.njuu.cf/TheAlgorithms/Python.git
synced 2023-10-11 13:06:12 +08:00
created perfect_cube.py (#2076)
* created perfect_cube.py To find whether a number is a perfect cube or not. * Update perfect_cube.py * Update perfect_cube.py * Update perfect_cube.py
This commit is contained in:
parent
19c3871b21
commit
3893ed30ca
16
maths/perfect_cube.py
Normal file
16
maths/perfect_cube.py
Normal file
@ -0,0 +1,16 @@
|
||||
def perfect_cube(n: int) -> bool:
|
||||
"""
|
||||
Check if a number is a perfect cube or not.
|
||||
|
||||
>>> perfect_cube(27)
|
||||
True
|
||||
>>> perfect_cube(4)
|
||||
False
|
||||
"""
|
||||
val = n ** (1 / 3)
|
||||
return (val * val * val) == n
|
||||
|
||||
|
||||
if(__name__ == '__main__'):
|
||||
print(perfect_cube(27))
|
||||
print(perfect_cube(4))
|
Loading…
Reference in New Issue
Block a user