In this assignment, we will track the balance, month by month, of a debt. This is similar to credit card calculators that can be found on the Web.
The user can enter the initial amount of the debt, the interest rate, and the amount of the monthly payment. All three of these should be floating-point numbers, for instance, the interest rate might be 13.4 or the monthly payment might be 150.00. If the user enters nothing, or something that is not a number, the program should give an error message and exit. Your program should not crash, no matter what input the user gives.
Every month the interest due is calculated and added to the balance, and then the monthly payment is subtraced from the balance. If the size of the monthly payment is big enough to cancel out the interest, then the balance shrinks and the debt is eventually paid off. If not, the balance will increase forever. This would cause the program to go into an infinite loop. Instead of doing that, the program should stop and tell the user that the monthly payment is insufficient.
The interest is compounded monthly; that is, every month, 1/12th of the annual interest rate is paid. So at an interest rate of 16% (typical for a credit card) the monthly interest due on a balance of $10,000 is (16% / 12) * $10,000 = $133.33. If the monthly payment is less than that, the balance will increase forever. If the monthly payment is $200, then the balance going forward after the first month would be $10,000+$133.33-$200.00 = $9133.33. Every month, your program should print out the balance going forward (after the deduction of interest and the payment).
The last month will require some special handling; the usual monthly payment would be more than the current balance plus the interest due in the last month. So the last payment, instead of being the usual amount, should be exactly the remaining balance plus interest.
Enter amount of debt: 1000
Month = 1
Enter interest rate: 12
Enter monthly payment: 300
Interest this month = 10.00
Balance going forward = 710.00
Total payments = 300.00
Month = 2
Interest this month = 7.10
Balance going forward = 417.10
Total payments = 600.00
Month = 3
Interest this month = 4.17
Balance going forward = 121.27
Total payments = 900.00
Month = 4
Interest this month = 1.21
Balance going forward = 0.00
Total payments = 1022.48
Press enter to exit
Here's another example:
Enter amount of debt: 8000
Enter interest rate: 14.5
Enter monthly payment: 50.00
You will need to make bigger payments.
At this rate you will never pay off the debt.
Press enter to exit
Going back and letting the user enter a larger payment would also be
a good way to handle a payment that is too small.
For accuracy - to avoid losing money due to round-off - the calculations should be done using floating-point numbers. To get nice looking output, use the format method to show only two decimal places.
You will need a function that checks to see if a string can be converted to a floating point number or not. The canBeFloat function in the file inputCheck.py does exactly this. In order to have access to this function, you need to put the file inputCheck.py in the same folder as your Python program (or have them both on the Desktop). Here is a little example of a program that uses the canBeFloat() function: checkFloats.py. Try putting both .py files in the same folder, and running checkFloats.py, and then look at checkFloats.py, to get an idea of how to use the couldBeFloat() function.