Where and how would I get this code to loop back to the original input to re enter an integer if the first integer did not have a cube root? "##Find the cuberoot of a perfect cube x= int(raw_input('Enter an integer:')) for ans in range(0, abs(x) + 1): if ans**3 == abs(x): break if ans**3 != abs(x): print x,'is not a perfect cube' else: if x<0: ans= -ans print 'Cube root of ' + str(x) + " is " + str(ans)"
rewrite your code
or write an additional line of code out side of your -->for loop<--
So your code would loop while x wasn't a perfect cube root?
I'd like to introduce the Boolean type. psuedocode: isCube = False while isCube != True: You can see where I'm going with this :)
@YaBoyX I really don't think he knows what you mean, his code is loosely put together.
I might be describing it wrong all together, I'm still a complete noob at this, so I might not even be describing a loop. I'm trying to get the program to allow me to re enter another integer if the first integer wasn't a perfect cube. As of now, when I enter any number, if it isn't a perfect cube, the program still ends and I have to run it again in order to enter a new integer. I'm trying to get it to return to the 'Enter an integer:' part without having to re run the program manually again
You might want to right a (while* loop) instead of using a (for* loop). Use a code similar to @YaBoyX .
The For loop needs to stay. It's what cycles through the iterations of the equation to find the cube root. What you need is a While Loop basically encapsulating all of your code telling the program to keep on running while a Boolean is FALSE. Once you do find the cube root, set the Boolean to true and the program will terminate once it's finished the current iteration. (Because that's what you want it to do)
I'm sorry. Not ALL of your code. You need to set the value of the Boolean first and THEN you create your while loop while nesting the For loop inside of it. Hope this helps! :)
Join our real-time social learning platform and learn together with your friends!