From 3893ed30cafd03265991f3209b5ef21ddd62b4c0 Mon Sep 17 00:00:00 2001 From: Vignesh Date: Thu, 11 Jun 2020 23:06:53 +0530 Subject: [PATCH] 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 --- maths/perfect_cube.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 maths/perfect_cube.py diff --git a/maths/perfect_cube.py b/maths/perfect_cube.py new file mode 100644 index 000000000..f65795ba8 --- /dev/null +++ b/maths/perfect_cube.py @@ -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))