On Mon, Mar 31, 2014 at 8:48 PM, Scott W Dunning <scott....@cox.net> wrote: > > On Mar 31, 2014, at 7:10 PM, Danny Yoo <d...@hashcollision.org> wrote: > Thanks for the info Danny! I’ll try that and I should be able to figure it > out with your help! > > The book I was referring to is greentreepress.
The reason I'm asking is I want to double check the example code. Checking... http://greenteapress.com/ ... but Green Tree Press publishes a few Python books. Hmmm. I will guess that you mean: Allen Downey's: "How to Think Like a Computer Scientist". Ah, found it. http://greenteapress.com/thinkpython/html/thinkpython008.html#toc81 But please, try to provide details. You tend to suppress helpful details. I would like to avoid guessing next time, so be aware that we don't see what you're thinking. Ok, I see now what you were looking at. But we need to wheel back around to one of your original questions. You said: > This is what the book has but it just gives me an endless loop. > > def square_root(a, eps=1e-6): > while True: > print x > y = (x + a/x) / 2 > if abs(y-x) < epsilon: > break > > round(square_root(9)) Go back and look at that text again: http://greenteapress.com/thinkpython/html/thinkpython008.html#toc81 and now see that the book does not present a function in that section. Instead, it's showing exploratory code. There's no function there, all the state is global, and it's not computing a return value. So you shouldn't be too surprised that the code the book is presenting, as a non-functional example, requires some adaptation before it works as a function. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor