I came across this problem online and used it on visualizer to see how this works. It looks to me that a new variable called guess was created using the for loop.
Question: Did the for loop create a new variable called "guess"? If not, how was the value of guess utilized outside the loop in the if/else statement?
cube = 8
for guess in range(cube+1):
if guess**3 >= abs(cube):
break
if guess**3 != abs(cube):
print(cube, "is not a perfect cube")
else:
if cube < 0:
guess = -guess
print("The cube root of", str(cube), "is", str(guess))
I'd highly appreciate some feedback on this. Thank you!