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


Groups > comp.lang.python > #76886

Re: Working with decimals

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin3!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed2a.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.006
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'example:': 0.03; 'sys': 0.07; 'string': 0.09; 'formatting': 0.09; 'warn': 0.09; 'cc:addr :python-list': 0.11; 'suggest': 0.14; "wouldn't": 0.14; '23,': 0.16; 'format?': 0.16; 'formatted': 0.16; 'formatting.': 0.16; 'messy': 0.16; 'url:openbookproject': 0.16; 'sat,': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'bit': 0.19; 'trying': 0.19; 'import': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'print': 0.22; 'necessary.': 0.24; 'math': 0.24; 'cc:2**0': 0.24; '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; 'decimal': 0.31; 'prints': 0.31; 'anyone': 0.31; 'figure': 0.32; 'url:python': 0.33; 'screen': 0.34; 'subject:with': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'url:listinfo': 0.36; 'method': 0.36; 'url:org': 0.36; 'should': 0.36; 'pm,': 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; 'term': 0.63; 'interest': 0.64; 'here': 0.66; 'link:': 0.72; '100': 0.79; 'url:php': 0.85; '1:47': 0.91; 'joel': 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=Ukid2V5jSdxC3jnsoswEJx8HKeIycBj5SNsWuWHEYRU=; b=xdkyhO+4NHJsXX5hgaxg7sYKCuZZfqzkzymdZcl7M60kBC2YrOe38nwJYe+bprRolV KJM0dy2X44krlMadsSqQGNmTFKChev4o0GFUW2YgJbmg5yedAF2EvkF2CFMtG5vOsMo0 bx6iafg5iWwN/SQIVa5x8ON8W7/S5yRZcz4v++vF1oX+iNi9gU1fETEfWtjO20T2N4ML R5fO44V1jW9qflbTUltPuXLAdoMlLVMTRsTu+J0tn0mEH3DOcp/opgLpoBAsDQ2JHYnW f4bkinVyJTQ0KBp0raVMYQw3Xn3eUpUQGbJE9WUt1GP+4F3J2u1hyKU7xDc3DkiwvIgC wwXQ==
MIME-Version 1.0
X-Received by 10.180.95.66 with SMTP id di2mr5282019wib.60.1408818063811; Sat, 23 Aug 2014 11:21:03 -0700 (PDT)
In-Reply-To <vrihv9l5sce3bkreceav5uhkaqdo9dqnri@4ax.com>
References <vrihv9l5sce3bkreceav5uhkaqdo9dqnri@4ax.com>
Date Sat, 23 Aug 2014 14:21:03 -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.13346.1408818070.18130.python-list@python.org> (permalink)
Lines 69
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1408818070 news.xs4all.nl 2909 [2001:888:2000:d::a6]:47061
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:76886

Show key headers only | View raw


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/

> 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.

>     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



-- 
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