24.8k views
0 votes
It is desired to create a mortgage estimator by writing a program containing a function. The user inputs the amount of loan (L), the loan term in number of months (W, and the annual interest rate (D in the script. The script then makes use of a function that accepts these values as inputs through its argument and calculates and returns the monthly payment and the total payments over the life of the loan. The monthly payment and the total payment could be calculated using the following expressions:

monthly payment 1-(1+ 1 112) N I/12 total payment Nxmonthly payment
Note that the interest rate must be expressed in decimal; for example, if the interest rate is 8% it must be entered as 0.08 Test your program for several scenarios and submit the results with the program listing.
The values of L, I, monthly payment, and total payment should be written to a file as shown below:
Interest Loan Amount Interest Months Monthly Payment Total Payment
0.06 10000 36
108 120000 0.05
0.07 85000 48
0.08 257000 240
0.05 320000 120

1 Answer

4 votes

Answer:

In Python:

L = int(input("Loan Amount: "))

N = int(input("Months: "))

I = float(input("Annual Interest Rate: "))

monthly_payment = round(L/((1 - (1 + I/12)**(-N))/(I/12)),2)

total_payment = round(N * monthly_payment,2)

f= open("outputfile.txt","a+")

f.write(str(L)+"\t\t"+str(I)+"\t\t"+str(N)+"\t\t"+str(monthly_payment)+"\t\t"+str(total_payment)+"\\")

Step-by-step explanation:

The next three lines get the required inputs

L = int(input("Loan Amount: "))

N = int(input("Months: "))

I = float(input("Annual Interest Rate: "))

Calculate the monthly payment

monthly_payment = round(L/((1 - (1 + I/12)**(-N))/(I/12)),2)

Calculate the total payment

total_payment = round(N * monthly_payment,2)

Open the output file

f= open("outputfile.txt","a+")

Write output to file

f.write(str(L)+"\t\t"+str(I)+"\t\t"+str(N)+"\t\t"+str(monthly_payment)+"\t\t"+str(total_payment)+"\\")

User Normanius
by
6.9k points