Answers for "number is perfect cube or not in python"

2

check if a number is perfect cube in python

x = int(input())
print(int(round(x ** (1. / 3))) ** 3 == x)
Posted by: Guest on August-24-2020
1

check if number is perfect cube python

def is_cube(n):
    guess = n**(1.0/3.0)
    iguess = int(guess)
    if iguess * iguess * iguess == n:
        print(True, "it's cubed root is", iguess)
        return
    iguess = iguess + 1
    if iguess * iguess * iguess == n:
        print(True, "it's cubed root is", iguess)
        return
    print(False, "it's cubed root is", guess)
    
is_cube(9) # No
is_cube(27) # Yes
Posted by: Guest on January-14-2021

Code answers related to "number is perfect cube or not in python"

Python Answers by Framework

Browse Popular Code Answers by Language