Question
1. Please modeify the code below so that it meets the requiements given. Also, please share code and show output. 2. Please do not write
1. Please modeify the code below so that it meets the requiements given. Also, please share code and show output.
2. Please do not write by hand.
REQUIREMENTS:
Mortgage Calculator.
Buying a house is one of the biggest financial transactions that many people ever undertake. Even a small difference in interest rates or monthly payments can make a large difference in how much you ultimately pay for your mortgage. However, these details are often buried in masses of paperwork--so it pays to be able to calculate the long-term cost of a mortgage yourself.
In a mortgage, the bank lends you a certain amount of principal to purchase a house at a certain interest rate. Every month, the amount you owe (the balance) first increases due to interest: 1/12 of the interest rate times the current balance. Then the balance decreases due to your monthly payment.
For example, suppose you borrow $100,000$100,000 at 5%5% annual interest, with $500$500 monthly payments. In the first month, the interest increases the balance by $416.67$416.67, and then your payment reduces it by $500$500, for a remaining balance of $99,916.67$99,916.67. In the second month, the interest charge is $416.32$416.32, and the remaining balance is $99,832.99$99,832.99.
If you continue this process, you get an amortization table like this:
month payment interest balance 1 500 416.67 99916.67 2 500 416.32 99832.99 3 500 415.97 99748.96 4 500 415.62 99664.58 5 500 415.27 99579.85 6 500 414.92 99494.76 7 500 414.56 99409.32 8 500 414.21 99323.53 9 500 413.85 99237.38 10 500 413.49 99150.87
You can also compute the total amount of time and money to pay off the mortgage. In this example, it takes 35 years and 11 months, and the total amount paid is approximately $215,458.84$215,458.84.
Create a mortgage calculator that takes as input the principal loan amount, interest rate, and monthly payment. As output, your calculator should generate an amortization table, and compute how many years and months it took to pay off the mortgage, and report the total amount of payments over that time.
Things to consider when implementing the calculator
For dollar values, only display two digits of precision after the decimal point.
You can assume that the bank will not round internally!
You must not round internally either!)
The final payment will almost certainly be smaller than the others, so be careful to check for that case so you don't end up with a negative balance. The final balance must be 0.
If the monthly payment is too small, the balance will go up every month!
If this happens, the program should stop and display an appropriate error message.
Manually stopping your code in this case is not considered a solution -- your submitted code must detect the problem itself, and not enter an infinite loop.
If you accidentally create an infinite loop during development and testing, interrupt or restart the kernel. See the Kernel menu up top.
Use the modulus or %% operator to separate the years and months.
Your program should only display the columns requested, and the rows should be formatted to appear under the appropriate heading.
ALSO USE A TEST CASE TO TEST IT WORKS PLEAS SHARE ALSO:
Use the following test cases to make sure your code matches calculations you can perform by hand. (Of course, if it does not match, please fix your code.) For each test case, print the results.
For each, use $500$500 for the principal, and an annual interest rate of 5%.
Monthly Payment: $100$100
Monthly Payment: $500$500
Monthly Payment: $1$1
CODE THAT NEEDS TO BE MODIFED.
# Python 3 program for mortgage calculator
import sys
import os
balance = 100000
interest_rate = 5.0
monthly_payment = 500
print("month" + "\t" + "payment" + "\t" + "interest" + "\t" + "balance" + " ")
M_value = 99000
month = 0
interest = 0
while(balance > M_value):
interest = balance * (interest_rate / 12)
month += 1
balance = balance + interest - monthly_payment
print(month + "\t" + monthly_payment + "\t" + interest + "\t" + balance + " "
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started