Python Version of Homework #3
Jan. 26th, 2009 10:33 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
# Finds out how many months it takes to pay off a $1000 purchase with no downpayment. rate = .015 # Interest rate of 1.5% per month. payment = 50 # Monthly payment. balance = 1000 # How much debt remains. months = 0 # How many monthly payments have been made so far. while balance > 0: thismonthsinterest = balance * rate # How much debt accrues this month balance = balance + thismonthsinterest - payment months += 1 print months, ' Interest: $%.2f' % thismonthsinterest, ' Balance: $%.2f' % balance
This gives the output:
1 Interest: $15.00 Balance: $965.00 2 Interest: $14.47 Balance: $929.48 3 Interest: $13.94 Balance: $893.42 4 Interest: $13.40 Balance: $856.82 5 Interest: $12.85 Balance: $819.67 6 Interest: $12.30 Balance: $781.97 7 Interest: $11.73 Balance: $743.70 8 Interest: $11.16 Balance: $704.85 9 Interest: $10.57 Balance: $665.42 10 Interest: $9.98 Balance: $625.40 11 Interest: $9.38 Balance: $584.79 12 Interest: $8.77 Balance: $543.56 13 Interest: $8.15 Balance: $501.71 14 Interest: $7.53 Balance: $459.24 15 Interest: $6.89 Balance: $416.13 16 Interest: $6.24 Balance: $372.37 17 Interest: $5.59 Balance: $327.95 18 Interest: $4.92 Balance: $282.87 19 Interest: $4.24 Balance: $237.11 20 Interest: $3.56 Balance: $190.67 21 Interest: $2.86 Balance: $143.53 22 Interest: $2.15 Balance: $95.68 23 Interest: $1.44 Balance: $47.12 24 Interest: $0.71 Balance: $-2.17
no subject
Date: 2009-01-27 04:29 pm (UTC)no subject
Date: 2009-01-27 05:18 pm (UTC)no subject
Date: 2009-01-27 05:30 pm (UTC)no subject
Date: 2009-02-15 04:15 am (UTC)