Re: Working with decimals part 2

2014-08-27 Thread Seymore4Head
On Tue, 26 Aug 2014 10:46:56 +1000, alex23 wuwe...@gmail.com wrote: On 26/08/2014 3:55 AM, Seymore4Head wrote: I changed the program just a little to give myself a little practice with number formats. The main thing I wanted to do was make the decimal points line up. The problem I am having

Working with decimals part 2

2014-08-25 Thread Seymore4Head
import sys import math def row1(number): return str(number).rjust(3) def row2(number): return str(format(number) ',.2f')) def row3(number): return '${:.2f}'.format(number) def row4(number): return '$' + str(format(math.floor(number * 100) / 100, ',.2f')) count = 0 payment = 0

Re: Working with decimals part 2

2014-08-25 Thread Chris Angelico
On Tue, Aug 26, 2014 at 3:55 AM, Seymore4Head Seymore4Head@hotmail.invalid wrote: For some reason, it is not working. If I try to use row2 I get this error: http://i.imgur.com/FgeF9c9.jpg Several meta-issues. Firstly, your subject line talks about 'decimal' again. You're actually working

Re: Working with decimals part 2

2014-08-25 Thread Mark Lawrence
On 25/08/2014 18:55, Seymore4Head wrote: import sys import math def row1(number): return str(number).rjust(3) def row2(number): return str(format(number) ',.2f')) def row3(number): return '${:.2f}'.format(number) def row4(number): return '$' + str(format(math.floor(number *

Re: Working with decimals part 2

2014-08-25 Thread MRAB
On 2014-08-25 18:55, Seymore4Head wrote: import sys import math def row1(number): return str(number).rjust(3) def row2(number): return str(format(number) ',.2f')) That line has to many ')'. The result of 'format' is a string, so there's no need to use 'str'. def row3(number):

Re: Working with decimals part 2

2014-08-25 Thread alex23
On 26/08/2014 3:55 AM, Seymore4Head wrote: I changed the program just a little to give myself a little practice with number formats. The main thing I wanted to do was make the decimal points line up. The problem I am having is with the print (count)(payment)(balance) line. While I don't want

Re: Working with decimals

2014-08-24 Thread Larry Hudson
On 08/23/2014 02:13 PM, Seymore4Head wrote: On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head I found this function that I will be saving for later. def make_it_money(number): import math return '$' + str(format(math.floor(number * 100) / 100, ',.2f')) (I still need more practice to

Re: Working with decimals

2014-08-24 Thread Seymore4Head
On Sun, 24 Aug 2014 00:04:29 -0700, Larry Hudson org...@yahoo.com wrote: On 08/23/2014 02:13 PM, Seymore4Head wrote: On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head I found this function that I will be saving for later. def make_it_money(number): import math return '$' +

Re: Working with decimals

2014-08-24 Thread Seymore4Head
On Sun, 24 Aug 2014 00:04:29 -0700, Larry Hudson org...@yahoo.com wrote: On 08/23/2014 02:13 PM, Seymore4Head wrote: On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head I found this function that I will be saving for later. def make_it_money(number): import math return '$' +

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 23 August 2014 23:53, Chris Angelico ros...@gmail.com wrote: On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau jos...@landau.ws wrote: On 23 August 2014 23:31, Chris Angelico ros...@gmail.com wrote: I'd say never is too strong (there are times when it's right to put an import inside a

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau jos...@landau.ws wrote: Is math not already imported by start-up? Why would it be? -- https://mail.python.org/mailman/listinfo/python-list

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau jos...@landau.ws wrote: Is math not already imported by start-up? Why would it be? It's easy to check, by the way: $ python -c import sys; print(sys.modules['math'])

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:19, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau jos...@landau.ws wrote: Is math not already imported by start-up? Why would it be? It's easy to check, by

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:25, Joshua Landau jos...@landau.ws wrote: On 24 August 2014 20:19, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau jos...@landau.ws wrote: Is math not already

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:25 PM, Joshua Landau jos...@landau.ws wrote: On 24 August 2014 20:19, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:12 PM, Joshua Landau jos...@landau.ws wrote: Is math

Re: Working with decimals

2014-08-24 Thread Ian Kelly
On Sun, Aug 24, 2014 at 1:29 PM, Joshua Landau jos...@landau.ws wrote: On 24 August 2014 20:25, Joshua Landau jos...@landau.ws wrote: On 24 August 2014 20:19, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014 at 1:17 PM, Ian Kelly ian.g.ke...@gmail.com wrote: On Sun, Aug 24, 2014

Re: Working with decimals

2014-08-24 Thread Joshua Landau
On 24 August 2014 20:40, Ian Kelly ian.g.ke...@gmail.com wrote: That's the same check I posted, just using the in operator instead of a straight lookup and raising an error. I think I need to take a break from the internet. This is the second time in as many threads that I've responded with

Re: Working with decimals

2014-08-24 Thread Larry Hudson
On 08/24/2014 08:12 AM, Seymore4Head wrote: [snip] I almost moved, but I was looking at the print out again for this one: print('%3d $%-13.2f $%-14.2f' % (count, payment, balance)) I can't understand why the $%-13.2f is pushed against the first column, but the $%-14.2f is not. It seems like

Re: Working with decimals

2014-08-24 Thread Seymore4Head
On Sun, 24 Aug 2014 14:24:19 -0700, Larry Hudson org...@yahoo.com wrote: On 08/24/2014 08:12 AM, Seymore4Head wrote: [snip] I almost moved, but I was looking at the print out again for this one: print('%3d $%-13.2f $%-14.2f' % (count, payment, balance)) I can't understand why the $%-13.2f is

Re: Working with decimals

2014-08-24 Thread Steven D'Aprano
Joshua Landau wrote: python -c import sys; print('math' in sys.modules) False An even easier check: python -c import time; a = time.time(); import math; b = time.time(); print(b-a) 0.0006012916564941406 python -c import math, time; a = time.time(); import math; b = time.time();

Re: Working with decimals

2014-08-24 Thread Chris Angelico
On Mon, Aug 25, 2014 at 12:16 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Joshua Landau wrote: python -c import sys; print('math' in sys.modules) False An even easier check: python -c import time; a = time.time(); import math; b = time.time(); print(b-a)

Re: Working with decimals

2014-08-24 Thread Steven D'Aprano
Chris Angelico wrote: I love this list. We can go off on a ridiculously long tangent, simply because I said that it's only *usually* best to put imports at the top of the file. We all agree that it normally is indeed best to hoist them, and here we are, arguing over measurement methods on

Re: Working with decimals

2014-08-24 Thread Chris Angelico
On Mon, Aug 25, 2014 at 12:51 PM, Steven D'Aprano steve+comp.lang.pyt...@pearwood.info wrote: Chris Angelico wrote: I love this list. We can go off on a ridiculously long tangent, simply because I said that it's only *usually* best to put imports at the top of the file. We all agree that it

Working with decimals

2014-08-23 Thread Seymore4Head
I am trying to do this example: http://openbookproject.net/pybiblio/practice/wilson/loan.php The instructions warn that floating point math can get messy so I cheated a little bit to get me going. I made my program work by using numbers that wouldn't get messy. Instead of using 6% interest I used

Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: I am trying to do this example: http://openbookproject.net/pybiblio/practice/wilson/loan.php The instructions warn that floating point math can get messy so I cheated a little bit to get me going. I made my

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick joel.goldst...@gmail.com wrote: On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: I am trying to do this example: http://openbookproject.net/pybiblio/practice/wilson/loan.php The instructions warn that floating

Re: Working with decimals

2014-08-23 Thread Joel Goldstick
On Sat, Aug 23, 2014 at 3:07 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick joel.goldst...@gmail.com wrote: On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head Seymore4Head@hotmail.invalid wrote: I am trying to do this example:

Re: Working with decimals

2014-08-23 Thread Mark Lawrence
On 23/08/2014 20:07, Seymore4Head wrote: Funny, I though using the web would be better than a book. I don't think so anymore. Using the web, it is hard to find square one tutorial text. Try typing something like python string formatting tutorial into your favourite search engine and

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 20:24:41 +0100, Mark Lawrence breamore...@yahoo.co.uk wrote: On 23/08/2014 20:07, Seymore4Head wrote: Funny, I though using the web would be better than a book. I don't think so anymore. Using the web, it is hard to find square one tutorial text. Try typing something

Re: Working with decimals

2014-08-23 Thread Mark Lawrence
On 23/08/2014 20:48, Seymore4Head wrote: Thanks for the links. The python-course looks like a beginner start. It raises one more question. Some have suggested using strings. I understand that strings and numbers are not the same thing. I know that converting numbers to strings can be

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 13:47:20 -0400, Seymore4Head Seymore4Head@Hotmail.invalid wrote: I am trying to do this example: http://openbookproject.net/pybiblio/practice/wilson/loan.php The instructions warn that floating point math can get messy so I cheated a little bit to get me going. I made my

Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 18:47, Seymore4Head Seymore4Head@hotmail.invalid wrote: Anyone care to suggest what method to use to fix the decimal format? It sounds like you want a primer on floating point. The documentation of the decimal module is actually a good read, although I don't doubt there are

Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 22:13, Seymore4Head Seymore4Head@hotmail.invalid wrote: def make_it_money(number): import math return ' + str(format(math.floor(number * 100) / 100, ',.2f')) So for one import math should never go inside a function; you should hoist it to the top of the file with all

Re: Working with decimals

2014-08-23 Thread Seymore4Head
On Sat, 23 Aug 2014 22:52:09 +0100, Joshua Landau jos...@landau.ws wrote: On 23 August 2014 18:47, Seymore4Head Seymore4Head@hotmail.invalid wrote: Anyone care to suggest what method to use to fix the decimal format? It sounds like you want a primer on floating point. The documentation of the

Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau jos...@landau.ws wrote: So for one import math should never go inside a function; you should hoist it to the top of the file with all the other imports. I'd say never is too strong (there are times when it's right to put an import inside a

Re: Working with decimals

2014-08-23 Thread Joshua Landau
On 23 August 2014 23:31, Chris Angelico ros...@gmail.com wrote: On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau jos...@landau.ws wrote: So for one import math should never go inside a function; you should hoist it to the top of the file with all the other imports. I'd say never is too strong

Re: Working with decimals

2014-08-23 Thread Chris Angelico
On Sun, Aug 24, 2014 at 8:47 AM, Joshua Landau jos...@landau.ws wrote: On 23 August 2014 23:31, Chris Angelico ros...@gmail.com wrote: On Sun, Aug 24, 2014 at 7:47 AM, Joshua Landau jos...@landau.ws wrote: So for one import math should never go inside a function; you should hoist it to the top