MITx 6.00.1x Python Notes: Paying Debt Off In a Year

Problem 1:
Write a program that calculates the minimum fixed monthly payment needed in order pay off a credit card balance within 12 months. By a fixed monthly payment, we mean a single number which does not change each month, but instead is a constant amount that will be paid each month.
In this problem, we will not be dealing with a minimum monthly payment rate.

The following variables contain values as described below:
balance
the outstanding balance on the credit card;
annual
annual interest rate as a decimal.
Assume that the interest is compounded monthly according to the balance at the end of the month (after the payment for that month is made). The monthly payment must be a multiple of $10 and is the same for all months. Notice that it is possible for the balance to become negative using this payment scheme, which is okay.

Solution:
We will set the fixed monthly payment to 10 at first. Then compute its remaining balance by calculating compounded interest. If the balance is greater than 0, then increased the fixed payment by 10.

Python code


Problem 2:
Similar to the above problem, but instead of paying the multiple of \$10, this time the fixed monthly payment will be the multiple of \$0.01.
The following variables contain values as described below:
balance
the outstanding balance on the credit card;
annual
annual interest rate as a decimal.

Solution
Trying to use bisection search.
The lower bound is $$\frac{\text{balance}}{12}$$
that is, the minimum monthly payment must be greater than the mean of balance (because we do not include interest).
While the upper bound should be the mean of the entire year balance on average, that is,
$$\frac{\text{balance}\times(1+\text{annual}/12)^{12}}{12}$$
Note that the minimum payment unit is $0.01.

Python code

2 条评论:


  1. I am really enjoying reading your well-written articles. It looks like you spend a lot of effort and time on your blog. I have bookmarked it and I am looking forward to reading new articles. Keep up the good work...

    python online training


    回复删除

  2. Well Done ! the blog is great and Interactive it is about MITx 6.00.1x Python Notes: Paying Debt Off In a Yearit is useful for students and Python Developers for more updates on python

    python online training

    回复删除