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)?

7th Feb 2019, 7:19 AM
Asri Sapari
Asri Sapari - avatar
1 Respuesta
+ 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.
7th Feb 2019, 7:26 AM
Anna
Anna - avatar