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: 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: References: Date: Sat, 23 Aug 2014 14:21:03 -0400 Subject: Re: Working with decimals From: Joel Goldstick To: Seymore4Head Content-Type: text/plain; charset=UTF-8 Cc: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head 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