Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Mark Tolonen
"Alan Gauld" wrote in message news:ht6v97$63...@dough.gmane.org... "Neven Gorsic" wrote I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. It depends how you define wrong. When I was at scvhool the rules f or rounding dec

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Alan Gauld
"Neven Goršić" wrote It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... The functions are not unreliable. That would imply they give out unpredictable answers. In fact the answers are completely predictable and consistent and correc

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Alan Gauld
"Neven Gorsic" wrote I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. It depends how you define wrong. When I was at scvhool the rules f or rounding decimals said that if it ended in 5 you rounded to the nearest even digit.

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread wesley chun
correct, it is a floating point issue regardless of language.. it's not just Python. you cannot accurately represent repeating fractions with binary digits (bits). more info specific to Python here: http://docs.python.org/tutorial/floatingpoint.html also, keep in mind that '%f' is not a rounding o

Re: [Tutor] loop raw input

2010-05-21 Thread Norman Khine
hi, thanks for the feedback, it is much appreciated. On Fri, May 21, 2010 at 7:54 PM, bob gailer wrote: > Also note that the database function creates a local variable "database" but > does nothing with it. > When the function terminates that variable is lost. > Did you intend to return it? yes,

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Emile van Sebille
On 5/21/2010 8:30 AM Neven Goršić said... Thanks! It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... The problem is with floats, and all languages suffer similarly. Most of us develop various techniques for avoiding these types of i

Re: [Tutor] loop raw input

2010-05-21 Thread bob gailer
Also note that the database function creates a local variable "database" but does nothing with it. When the function terminates that variable is lost. Did you intend to return it? Also it is not good practice to use the same name for a function and a variable. -- Bob Gailer 919-636-4239 Chapel

Re: [Tutor] loop raw input

2010-05-21 Thread bob gailer
On 5/21/2010 5:35 AM, Norman Khine wrote: hello, i have this script, but i am stuck at the loop, if the user types an incorrect database id: http://paste.lisp.org/+25D3 how would i write the exception correctly? Which line of code could raise the ValueError exception? That line should be

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks for the assistance and the article. Neven -- On Fri, May 21, 2010 at 5:35 PM, Lie Ryan wrote: > On 05/22/10 01:30, Neven Goršić wrote: > > Thanks! > > It's pity that Python has such unreliable functions so you never know in > > advanced when you will hit new one ...

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/22/10 01:30, Neven Goršić wrote: > Thanks! > It's pity that Python has such unreliable functions so you never know in > advanced when you will hit new one ... Well, it's not Python but the machine. Floating point number is not Real numbers; there are certain limitations imposed by physical l

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Thanks! It's pity that Python has such unreliable functions so you never know in advanced when you will hit new one ... --- On Fri, May 21, 2010 at 2:14 PM, Lie Ryan wrote: > On 05/21/10 20:17, Neven Goršić wrote: > > Hi! > > > > I run into Python error in rounding and n

Re: [Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Lie Ryan
On 05/21/10 20:17, Neven Goršić wrote: > Hi! > > I run into Python error in rounding and not know how to predict when it will > occur in order to prevent wrong result. That's because it's floating point number. > What can I do to assure accurate result? Use decimal module to do precise control

[Tutor] Python 2.5.4 - error in rounding

2010-05-21 Thread Neven Goršić
Hi! I run into Python error in rounding and not know how to predict when it will occur in order to prevent wrong result. What can I do to assure accurate result? >>> "%.2f" % 0.445 '0.45' correct >>> "%.2f" % 0.455 '0.46' correct

[Tutor] loop raw input

2010-05-21 Thread Norman Khine
hello, i have this script, but i am stuck at the loop, if the user types an incorrect database id: http://paste.lisp.org/+25D3 how would i write the exception correctly? norman -- %>>> "".join( [ {'*':'@','^':'.'}.get(c,None) or chr(97+(ord(c)-83)%26) for c in ",adym,*)&uzq^zqf" ] ) __