Python program to find cube root of perfect cube numbers

Program:


#finding cube root
#Enter The number 
x=int(raw_input('Enter the number :'))
#initialize the variable to zero
ans=0
#using Simple While loop increment ans until cube of the 
#answer less than input
while ans**3<x:
    ans+=1
#if entered number is not perfect cube indicate that in console    
if ans**3!=x:
 print(str(x)+' is not perfect cube')
#if the entered number is perfect cube display the cube root  
else:

 print('cube root of '+str(x)+' is: '+str(ans))    
    

Note: Please do not change indentation while executing the program 




Output:





Comments