Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76891

Re: Working with decimals

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <joel.goldstick@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'python,': 0.02; 'example:': 0.03; 'tutorial': 0.03; 'column': 0.07; 'sys': 0.07; 'string': 0.09; 'anymore.': 0.09; 'formatting': 0.09; 'funny,': 0.09; 'warn': 0.09; 'cc:addr:python-list': 0.11; 'suggest': 0.14; "wouldn't": 0.14; 'books': 0.15; '23,': 0.16; '>>on': 0.16; 'format?': 0.16; 'formatted': 0.16; 'formatting.': 0.16; 'messy': 0.16; 'spacing': 0.16; 'stumbled': 0.16; 'url:openbookproject': 0.16; 'usenet': 0.16; 'sat,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'library': 0.18; 'bit': 0.19; 'trying': 0.19; 'thanks.': 0.20; 'command': 0.22; '>>>': 0.22; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'necessary.': 0.24; 'text.': 0.24; 'math': 0.24; 'cc:2**0': 0.24; 'references': 0.26; 'web.': 0.26; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'message-id:@mail.gmail.com': 0.30; 'skip:( 20': 0.30; 'url:mailman': 0.30; 'correctly.': 0.31; 'decimal': 0.31; 'prints': 0.31; 'anyone': 0.31; 'figure': 0.32; 'python.org': 0.32; 'url:python': 0.33; 'moment': 0.34; 'screen': 0.34; 'could': 0.34; 'subject:with': 0.35; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'web,': 0.36; 'url:org': 0.36; 'should': 0.36; 'tired': 0.38; 'pm,': 0.38; 'rather': 0.38; 'little': 0.38; '12,': 0.39; 'url:2012': 0.39; 'use.': 0.39; 'url:mail': 0.40; 'balance': 0.61; 'numbers': 0.61; 'first': 0.61; 'term': 0.63; 'interest': 0.64; 'more': 0.64; 'here': 0.66; 'book.': 0.68; 'link:': 0.72; 'square': 0.74; '100': 0.79; 'url:php': 0.85; '1:47': 0.91; 'joel': 0.91; 'try.': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=Pdl7FbkJPNcvK+sjnH/ysywMRTxJySUYfLDp1iMCR0M=; b=VcdxOk5ulK1pf1xvjn528PYRey5dD4YRYV055/MGfqZHdlZWglsomMUuXnHT4VtsSd iHDfee4y2EchuLIh4fkq/ISzPT/mORIUykJG9aj09iQ339hkIepViJMv/aVrGG5aYosK 3cbVkK2ejrTt0mWDTWSiajIh5WHWtQzpAE+p7DtMi8u/+N1J1cKEoTxG6G6Rc/S0jnmZ y2G1Sdv25vMynjdECnHOJWu3GNgdB2WkEiWZaGFVNzzGOyCA0FeVYCm2PogZzoFdryt8 yQcYo8Lo/XadlL2726cqRN829fPRk9TSM2D/c+AtClc8hywYyN+FkU72TAqycoIFFbFe Mkkw==
MIME-Version 1.0
X-Received by 10.180.24.35 with SMTP id r3mr5244508wif.71.1408821764269; Sat, 23 Aug 2014 12:22:44 -0700 (PDT)
In-Reply-To <d6phv9tqakjs6h6p1un36k68uvsu85aku1@4ax.com>
References <vrihv9l5sce3bkreceav5uhkaqdo9dqnri@4ax.com> <mailman.13346.1408818070.18130.python-list@python.org> <d6phv9tqakjs6h6p1un36k68uvsu85aku1@4ax.com>
Date Sat, 23 Aug 2014 15:22:44 -0400
Subject Re: Working with decimals
From Joel Goldstick <joel.goldstick@gmail.com>
To Seymore4Head <Seymore4Head@hotmail.invalid>
Content-Type text/plain; charset=UTF-8
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13349.1408821771.18130.python-list@python.org> (permalink)
Lines 95
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408821771 news.xs4all.nl 2892 [2001:888:2000:d::a6]:38103
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76891

Show key headers only | View raw


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.goldstick@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 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 10 and instead of using 12 months,
>>> I used 10.
>>>
>>> I managed to get it working and formatted just like they wanted it,
>>> but now I want to try to use any numbers.  It has been hard to figure
>>> out which method to use.
>>>
>>You need to learn about string formatting.  Here is a good link:
>>http://mkaz.com/2012/10/10/python-string-format/
>>
> Thanks.  I will give that a try.
>
>>> Here is the working program.
>>>
>>> import sys
>>> count = 0
>>> payment = 0
>>> borrowed = 100
>>> rate = 10
>>> term = 10
>>> interest=borrowed*rate*.01     #(*1)
>>> balance = borrowed + interest
>>> print ("Loan calculator")
>>> print ("")
>>> print ("Amount borrowed: ", borrowed)
>>> print ("Interest rate: ", rate)
>>> print ("Term: (months)", term)
>>> print ("")
>>> print ("Amount borrowed:" , borrowed)
>>> print ("Total interest paid:" , interest)
>>> print ("")
>>> print ("")
>>> print ("            Amount      Remaining")
>>> print ("Pymt#        Paid        Balance")
>>> print ("-----       ------       ----------")
>>> while count <=term:
>>>
>>>
>>>     print (repr(count).rjust(3), repr(payment).rjust(13),
>>> repr(balance).rjust(14))
>>>
>>>
>>I don't understand why you are using repr(..)  It is not necessary.
>>
> Would you please change the line to something you feel that is more
> appropriate?  That was the first command I stumbled on that I could
> use to get the column spacing correctly.
> I have contacted my local library to get a couple of books on Python,
> but at the moment all I have is the web.
>
> 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.
>

You should go to python.org and take a look at the tutorial.  There
are lots of references to other sites there as well
>
>>>     payment = (borrowed + interest)/term
>>>     balance = balance - payment
>>>     count = count + 1
>>>
>>> What should I use to make the formatting come out correctly when the
>>> program prints "payment" and "balance" using decimal format?
>>>
>>> If you change the "rate" from 10 to 6 and the "term" from 10 to 12,
>>> the screen gets very messy.
>>>
>>> Anyone care to suggest what method to use to fix the decimal format?
>>> --
>>> https://mail.python.org/mailman/listinfo/python-list
>
> I would rather just use Usenet for the moment.  Until the group gets
> tired of nursing the rookie.
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 13:47 -0400
  Re: Working with decimals Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-23 14:21 -0400
    Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 15:07 -0400
      Re: Working with decimals Joel Goldstick <joel.goldstick@gmail.com> - 2014-08-23 15:22 -0400
      Re: Working with decimals Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-23 20:24 +0100
        Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 15:48 -0400
          Re: Working with decimals Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-23 21:31 +0100
  Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 17:13 -0400
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 22:47 +0100
    Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-24 08:31 +1000
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 23:47 +0100
    Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-24 08:53 +1000
    Re: Working with decimals Larry Hudson <orgnut@yahoo.com> - 2014-08-24 00:04 -0700
      Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 10:58 -0400
      Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 11:12 -0400
        Re: Working with decimals Larry Hudson <orgnut@yahoo.com> - 2014-08-24 14:24 -0700
          Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-24 19:07 -0400
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:12 +0100
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:17 -0600
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:19 -0600
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:25 +0100
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:29 +0100
      Re: Working with decimals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-25 12:16 +1000
        Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-25 12:27 +1000
          Re: Working with decimals Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-25 12:51 +1000
            Re: Working with decimals Chris Angelico <rosuav@gmail.com> - 2014-08-25 13:01 +1000
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:37 -0600
    Re: Working with decimals Ian Kelly <ian.g.kelly@gmail.com> - 2014-08-24 13:40 -0600
    Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-24 20:49 +0100
  Re: Working with decimals Joshua Landau <joshua@landau.ws> - 2014-08-23 22:52 +0100
    Re: Working with decimals Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-23 18:03 -0400

csiph-web