Re: [Tutor] Division doesn't work

2007-01-18 Thread Danny Yoo
On Thu, 18 Jan 2007, Johan Geldenhuys wrote: > Thanks at lot. Something as simple as that... No, don't feel bad about it: integer division is a bad "gotcha!" in Python. Integer division is known to be suprising, and it'll eventually be replaced by true division in Python 3: http://www.

Re: [Tutor] Division doesn't work

2007-01-18 Thread Zara
On Thu, 18 Jan 2007 13:09:48 +0100, Geoframer <[EMAIL PROTECTED]> wrote: >You assign s as an integer... it should be a float to get the right >result... <...> Yes, that is the wordt defect of Python: its inability to read programmer mind and detect the rteal programmer intentions. Zara __

Re: [Tutor] Division doesn't work

2007-01-18 Thread Kent Johnson
Johan Geldenhuys wrote: > Hi all, > > In my script I want to convert 14105 bytes to kilobytes and and this is > what I do: > >> >> s = 14105 >> >> print '%0.2f' % (s/1024) > 13.00 > > This not correct and I don't know why. The answer is 13.77. > > Any pointers please that would help my in

Re: [Tutor] Division doesn't work

2007-01-18 Thread Johan Geldenhuys
Thanks at lot. Something as simple as that... J _ From: Geoframer [mailto:[EMAIL PROTECTED] Sent: 18 January 2007 02:10 PM To: Johan Geldenhuys Cc: tutor@python.org Subject: Re: [Tutor] Division doesn't work You assign s as an integer... it should be a float to get the right r

Re: [Tutor] Division doesn't work

2007-01-18 Thread Geoframer
Or actually an even easier way is to just to divide bij a float and the end result will also be a float. So in your case divide bij 1024.0 ;-) In [21]: s=14105 In [22]: s/1024.0 Out[22]: 13.7744140625 HTH - Geofram On 1/18/07, Geoframer <[EMAIL PROTECTED]> wrote: You assign s as an intege

Re: [Tutor] Division doesn't work

2007-01-18 Thread Geoframer
You assign s as an integer... it should be a float to get the right result... So either define s as s = 14105.0 or as s = float(14105) it'll then result in the right answer : In [17]: s=14105.0 In [18]: s/1024 Out[18]: 13.7744140625 In [19]: s = float(14105) In [20]: s/1024 Out[20]: 13.7744

[Tutor] Division doesn't work

2007-01-18 Thread Johan Geldenhuys
Hi all, In my script I want to convert 14105 bytes to kilobytes and and this is what I do: >>> s = 14105 >>> print '%0.2f' % (s/1024) 13.00 This not correct and I don't know why. The answer is 13.77. Any pointers please that would help my in the right direction? Thanks Johan -- No vi