Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In this assignment you will write a program called \"loan.py\" that calculates m

ID: 3543396 • Letter: I

Question

 In this assignment you will write a program called "loan.py"  that calculates monthly mortgage payments, and some additional information. To begin, define a function called "payment", which asks the user for four pieces of information:  1) The amount of the loan. Use a variable named "p" for the amount of the loan. 2) The annual percentage interest rate. Use a variable named "apr". 3) The number of years of the loan. Use a variable named "years". 4) The maximum monthly payment that the user can afford. Use a variable named "max".  Then write the rest of the function payment  to calculate the monthly amount that must be paid for this loan. The result is assigned to a variable named "m". The value of m is calculated as follows:  1) multiply years times 12 and assign the result to a variable called "n". n is the number of monthly payments that must be made.  2) divide apr by 100.00 and assign the result back to apr. For example, this converts an input of 7 to 0.07. If you divide by 100 (without the decimal point), bad things happen - that will be explained later in the class. So be sure to use 100.00 here.  3) divide apr by 12 and assign the result to a variable called "i". i is the monthly interest rate.  4) compute the monthly payment and assign the result to the variable m. The formula for computing m is based on p, i, and n, and is explained in detail at:  http://www.wikihow.com/Calculate-Mortgage-Payments  Just look at the parts in color, i.e., starting where it says: "Examine the Equation for Mortgage Payments"   The exponentiation operator in Python, **,  is explained on page 34 of our text.  Then the function payment should print out the values of p, apr, years, n, i, and m, along with some other information (see the execution example below).  Then the function payment should compare m to max, to determine if the user can afford the loan.  That ends the description of the function called ``payment". To repeat, your assignment is to first write the details for function ``payment".  Then for the rest of the loan.py program, write code that asks  the user how many loan calculations they want to do, using a variable called "again". Then call payment() that many times.  Here is an example of an execution of loan.py in IDLE:  >>> How many different loans do you want to calculate? 2  Loan Calculation Number  1  What is the amount of the loan? 100000 What is the annual % interest rate? i.e., print x for an x% annual interest rate 5 How many years will the loan be? 20 What is the maximum you can afford to pay per month? 2300 100000 0.05 20 240 0.004166666666666667 659.9557392166587  Your monthly payments will be  659.9557392166587  dollars The total amount you will pay is  158389.37741199808 dollars The total amount of interest you will pay on a loan of  100000  dollars is  58389.37741199808 Yes, you can afford this loan.  Loan Calculation Number  2  What is the amount of the loan? 34500 What is the annual % interest rate? i.e., print x for an x% annual interest rate 6.7 How many years will the loan be? 10 What is the maximum you can afford to pay per month? 250 34500 0.067 10 120 0.005583333333333333 395.2603861570672  Your monthly payments will be  395.2603861570672  dollars The total amount you will pay is  47431.24633884807 dollars The total amount of interest you will pay on a loan of  34500  dollars is  12931.246338848068 No, you cannot afford this loan.  Thank you for using our services. Good-Bye >>>   As an aid to checking your program, the following link leads to an on-line calculator where you can put in data, and it will calculate m. So you can try out different numbers there to be sure that your program is getting the same answer.  http://www.bankrate.com/partners/sem/mortgage-calculator.aspx


Notes: Need full program. If your program is more advanced than a very very basic introduction knowledge, it is useless and I won't give points

Explanation / Answer

def payment(x):

p=input("Enter The amount of the loan : ")

apr=input(" Enter The annual percentage interest rate: ")

years=input(" Enter The number of years of the loan: ")

max=input(" Enter The maximum monthly payment that the user can afford: ")

n=(int(years))*12

apr=(int(apr))/100.00

i=apr/12

m=((int(p))*i*((1+i)**n))/(((1+i)**n)-1)

tot=m*n

s="Loan Calculation Number"

print (s,x)

print (p,apr,years,n,i,m)

u="Your monthly payments will be "

v=" dollars"

print (u,m,v)

w="The total amount you will pay is "

print (w,tot,v)

y=" is "

x="The total amount of interest you will pay on a loan of "

print (x,p,v,y,tot)

if m<=(int(max)):

a="Yes, you can afford this loan."

print (a)

else:

b="No, you can not afford this loan."

print (b)

def main():

t=input("How many different loans do you want to calculate : ")

j=int(t)

k=1

while k<=j:

payment(x=k)

k=k+1

main()