[Tutor] home_finance.py
Ian Witham
witham.ian at gmail.com
Wed Sep 26 04:56:50 CEST 2007
On 9/26/07, Christopher Spears <cspears2002 at yahoo.com> wrote:
>
> I'm working on a problem in Chapter 5 of Core Python
> Programming(2nd Edition). I am supposed to write a
> script that take an opening balance and a monthly
> payment from the user. The script then displays the
> balance and payments like so:
>
>
> Enter opening balance: 100
> Enter monthly payment: 16.13
> Amount Remaining
> Pymnt# Paid Balance
> 0 0.00 100.00
> 1 16.13 83.87
> 2 16.13 67.74
> 3 16.13 51.61
> 4 16.13 35.48
> 5 16.13 19.35
> 6 16.13 3.22
> 7 3.22 0.00
>
> Here is what I have written so far:
>
> #!/usr/bin/env python
>
> balance = float(raw_input("Enter opening balance: "))
> payment = float(raw_input("Enter monthly payment: "))
>
> print "\tAmount\tRemaining"
> print "Pymnt#\tPaid\tBalance"
>
> payment_num = 0
> print "%d\t%.2f\t%.2f" % (payment_num,0,balance)
>
> while balance >= 0:
> payment_num = payment_num + 1
> if balance > 0:
You have: if balance > 0:
You should be checking whether the remaining balance is greater than the
payment amount, not whether it is greater than 0.
This is probably just a typo as it looks like you're on the right track.
Ian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070926/5c4cb42f/attachment.htm
More information about the Tutor
mailing list