Skip to content

Commit 3893ed3

Browse files
authored
created perfect_cube.py (TheAlgorithms#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
1 parent 19c3871 commit 3893ed3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

maths/perfect_cube.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
def 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+
14+
if(__name__ == '__main__'):
15+
print(perfect_cube(27))
16+
print(perfect_cube(4))

0 commit comments

Comments
 (0)