Working with decimals

Seymore4Head Seymore4Head at Hotmail.invalid
Sat Aug 23 15:07:10 EDT 2014


On Sat, 23 Aug 2014 14:21:03 -0400, Joel Goldstick
<joel.goldstick at gmail.com> wrote:

>On Sat, Aug 23, 2014 at 1:47 PM, Seymore4Head
><Seymore4Head at 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.


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



More information about the Python-list mailing list