I'm a beginner in python and have written a code to check if a number is a cube of a whole number. The code seems to be working fine for some values, however for some (even whole cubes) it prints the cube root as (x-0.000000004
, x
being cube root). Example it will give 3.9999999996
as the cube root of 64 but will print 2,5 for 8,125 . Any thoughts?
n=int(input("Please enter the number: "))
print (n)
x=n**(1/3)
print (x)
if x==int(x):
print ('%s is a whole cube'%(n))
else:
print ('%s is not a whole cube'%(n))
Ignore the intermediate print statements, they're just for line-by-line debugging.