[Tutor] Need help with rewriting script to use Decimal module

Dick Moores rdm at rcblue.com
Thu Jan 4 08:50:13 CET 2007


At 01:17 PM 1/2/2007, Terry Carroll wrote:
>On Mon, 1 Jan 2007, Dick Moores wrote:
>
> > bestFracForMinimumError() is only a small part of a program I wrote
> > long ago, called frac.py
>
>Dick, if your goal is to have a routine to get the fraction with the least
>possible error (as opposed to learing how to use Decimal), have a look at
>this recipe from the Python Cookbook:
>
>  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52317

Terry, I just noticed that farey(0.36, 10) returns (1, 3), a pretty 
big miss, IMO. The correct fraction with smallest error and maximum 
denominator of 10 is 3/8, which I'm proud to say my klunky frac.py 
(<http://www.rcblue.com/Python/fracForWeb.py>) produces.

Be that as it may, farey() is an amazing program. I appreciate the 
fast replies from you and Danny to my plea for explication. I'm still 
working through them.

Dick







More information about the Tutor mailing list