Ask your own question, for FREE!
MIT 6.00 Intro Computer Science (OCW) 15 Online
OpenStudy (anonymous):

how is abs(x) - ans**3 a decrementing function, as explained in the Lecture 3?

OpenStudy (anonymous):

Hang on, I'll have a look at it

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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

OpenStudy (anonymous):

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.

OpenStudy (anonymous):

Thatś right

OpenStudy (anonymous):

thanks for quick help, r u taking this course or have already completed?

OpenStudy (anonymous):

No I'm doing it right now I'm working on problem set 4 at the moment

OpenStudy (anonymous):

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

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!