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: 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: References: Date: Sat, 23 Aug 2014 15:22:44 -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: 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 On Sat, Aug 23, 2014 at 3:07 PM, Seymore4Head wrote: > On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick > wrote: > >>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/ >> > 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