Question

Data Programming l - Python Write a program that takes the terms of a loan as...

Data Programming l - Python

Write a program that takes the terms of a loan as inputs(principal, interest rate as a %, number of payments per year, and the total number of years), computes the interest paid over the life of the loan and produces the output shown below. The examples shown below are for:

  1. Borrowing $100,000 for a condo financed over 30 years with 12 payments per year at 4.5%.
  2. Borrowing $25,000 for a car financed over 6 years with 12 payments per year at 3.5%.

The total amount paid for a loan (accrued amount) is given by the formula below where A is the amount accrued over the life of the loan including principal, P is the principal, r is the rate as a decimal, n is the number of payments made per year and t is the life of the loan in years. Use the round function to have at most 1 decimal place in the answer.
A = P(1+r/n)nt{"version":"1.1","math":"<math xmlns="http://www.w3.org/1998/Math/MathML"><mi>A</mi><mo>&#xA0;</mo><mo>=</mo><mo>&#xA0;</mo><mi>P</mi><mo>(</mo><mn>1</mn><mo>+</mo><mi>r</mi><mo>/</mo><mi>n</mi><msup><mo>)</mo><mrow><mi>n</mi><mi>t</mi></mrow></msup></math>"}

Input:

a) python C:\Users\neda\DataProgramming\M1\assign1-4.py 100000 4.5 12 30

b) python C:\Users\neda\DataProgramming\M1\assign1-4.py 25000 3.5 12 6

Output:

a) Interest Paid: $284769.8

b) Interest Paid: $5832.5

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#save the file as assign1-4.py
#!/usr/bin/python
#import sys module to get command line arguments
import sys
#Get values from the command line using sys.argv
#and assign to principal ,rate ,payments, years
principal=float(sys.argv[1])
rate=float(sys.argv[2])/100
payments=float(sys.argv[3])
years=float(sys.argv[4])


#calculate the future value based on the below formula
futureValue=principal*pow((1+rate/payments),payments*years)
#calculate interest paid
interestPaid=futureValue-principal
print('Interest Paid:$',round(interestPaid,2))

------------------------------------------------------------------------------------------------------------------------

Sample output:

sample run1:

assign1-4.py 100000 4.5 12 30

Interest Paid:$ 284769.8

Sample run2:

assign1-4.py 25000 3.5 12 6


Interest Paid:$ 5832.53

Add a comment
Know the answer?
Add Answer to:
Data Programming l - Python Write a program that takes the terms of a loan as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • The program is in python :) Write a code program to calculate the mortgage payment. The...

    The program is in python :) Write a code program to calculate the mortgage payment. The equation for calculating the mortgage payment is: M = P (1+r)n (1+r)n-1 Where: M is your monthly payment P is your principal r is your monthly interest rate, calculated by dividing your annual interest rate by 12. n is your number of payments (the number of months you will be paying the loan) Example: You have a $100,000 mortgage loan with 6 percent annual...

  • JK’s is borrowing $132,000 for three years at an APR of 7.6 percent. The loan calls...

    JK’s is borrowing $132,000 for three years at an APR of 7.6 percent. The loan calls for the principal balance to be reduced by equal amounts over the life of the loan. Interest is to be paid in full each year. The payments are to be made annually at the end of each year. How much will be paid in interest over the life of this loan?

  • Write a python program for the below question? Car Loan If A dollars is borrowed at...

    Write a python program for the below question? Car Loan If A dollars is borrowed at r% interest compounded monthly to purchase a car with monthly payments for n years, then the monthly payment is given by the formula monthly payment = i / 1 - (1 + i)-12n . A where i = r/1200. Write a program that calculates the monthly payment after the user gives the amount of the loan, the interest rate, and the number of years.

  • Suppose you have $250,000 of loan. The terms of the loan are that the yearly interest...

    Suppose you have $250,000 of loan. The terms of the loan are that the yearly interest is 6% compounded quarterly. You are to make equal quarterly payments of such magnitude as to repay this loan over 30 years. (Keep all your answers to 2 decimal places, e.g. XX.12.) (a) How much are the quarterly payments? Ans: 4504.63 (b)  After 5 years' payments, what principal remains to be paid? Ans: 232550.19 (c) How much interest is paid in the first quarter of...

  • Installment Loan Schedule Assume you are to borrow money, the loan amount, at an annual interest...

    Installment Loan Schedule Assume you are to borrow money, the loan amount, at an annual interest rate to be paid in equal installments each period Loan Amount $ 25,000 9.90% Annual Interest Rate Periods per year 12 Years to payback See Table B.3 in book. 47.17454194 FACTOR = [1 -(1 / ((1R)An)]/ R Factor $ Equal Payments 529.95 let R = period interest rate number of periods to payback loan let n Number of periods: 60 Reduction in Principal Interest...

  • MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay-...

    MATLAB!!! CAN SOMEONE SOLVE THIS PROBLEM ON MATLAB?? THANK YOU PART B: HOUSING LOAN CALCULATOR In this part of the assignment, you are expected to develop a program that calculates housing loan pay- ments based on compound interest formulas The program should prompt a user to input the amount borrowed (principal), p, the number of monthly payments, n, and an annual interest rate in R percent. The program should convert the annual interest rate R into a monthly interest rate...

  • Sarah secured a bank loan of $200,000 for the purchase of a house. The mortage is...

    Sarah secured a bank loan of $200,000 for the purchase of a house. The mortage is amortized through monthly payments of $1,687.71 for a term of 15 years, at an interest rate of 6% per year compounded monthly. a. Determine the total amount of interest to be paid over the life of this loan. b. If she sells her house in 5 years, how much will Sarah still owe on her house (what is her outstanding principal in 5 years)?

  • C# Create an application that will allow a loan amount, interest rate, and number of finance...

    C# Create an application that will allow a loan amount, interest rate, and number of finance years to be entered for a given loan. Determine the monthly payment amount. Calculate how much interest will be paid over the life of the loan. Display an amortization schedule showing the new balance after each payment is made. Design an object-oriented solution. Use two classes. Loan class: characteristics such as the amount to be financed, rate of interest, period of time for the...

  • B c D E F G H $ $ 400,000.00 Original Loan 4.50% APR Interest Rate...

    B c D E F G H $ $ 400,000.00 Original Loan 4.50% APR Interest Rate 30 Term in Years HARDCODE ANSWERS How many months does it take to pay off the loan? Please Review Month Outstanding Principal USE ONLY FORMULAS IN THIS CHART Interest Principal Total Payment Additional Principal 1 What is the total payments paid over the loan? 2 3 Please Review 4 What is the total interest paid over the loan? Please Review 5 6 7 How...

  • An amount of $15,000 is borrowed from the bank at an annual interest rate 12% h...

    An amount of $15,000 is borrowed from the bank at an annual interest rate 12% h Calculate the repavment amounts if the loan ($15 000) will be repaid in two equal installments of $7.500 each, paid at the end of second and fourth years respectively. Interest will be paid each year Click the icon to view the interest and annuity table for discrete compounding when i- 12%% per year . a. The equal end-of-year payments required to pay off the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT