0
why does this not happen in this Cube code
Hi there, In this code: x = int(input( âEnter an integer: â)) and = 0 while ans**3 < x: ans = ans + 1 if ans**3 != x: print(str(x) + â is not a perfect cubeâ) else: print(âCube root of â + str(x) + â is â + str(ans)) Why does the program not print each time the ans**3 is not equal to x? For e.g the perfect cube of 1000 is 10. So technically it should print when ans is from 1-9 since the condition is ans**3 != (x)?
1 Answer
+ 1
Don't use "and" as a variable name and replace all accents (`) with regular quotes (' or ").
If you want it to output that x is not a perfect cube each time (why?), you need to make the if statement a part of the while block by indenting it.