how is abs(x) - ans**3 a decrementing function, as explained in the Lecture 3?
Hang on, I'll have a look at it
This was the code right? ``` #Find the cube root of a perfect cube x = int(raw_input('Enter an integer: ')) ans = 0 while ans*ans*ans < abs(x): ans = ans + 1 #print 'current guess =', ans if ans*ans*ans != abs(x): print x, 'is not a perfect cube' else: if x < 0: ans = -ans print 'Cube root of ' + str(x) + ' is ' + str(ans) ```
so ans increases by 1 each time the code within the whele loop is carried oud so abs(x) = constant in the loop the first time ans = 0 , so the value of the Decrematial function is abs(x) the second time ans = 1 , so ....................................................is abs(x)-1 the third time ans = 3 .......................................................... abs(x)-8 and so on
okay, i sort of understood this, but my expectation was to have a line of code like `abs(x) - ans**3` in the python code. So this means that the decremented function need not be a line of code, we have to figure out a decremented function.
Thatś right
thanks for quick help, r u taking this course or have already completed?
No I'm doing it right now I'm working on problem set 4 at the moment
Iǘe fanned you, so that I can find you back as someone who is also doing this course at the moment Its nice to discuss the material now and then
Join our real-time social learning platform and learn together with your friends!