0% found this document useful (0 votes)
14 views

Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Assignment 1

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

Assignment 1

Date: 20-12-2022

1. Car loans are a type of amortizing loan. Let’s say you took out an auto loan for
$20,000
with an APR(Annual Percentage Rate) of 6 percent and a five-year repayment
timeline.
Here’s how you would calculate loan interest payments.
 Divide the interest rate you’re being charged by the number of payments you’ll
make each year, usually 12 months.
 Multiply that figure by the initial balance of your loan, which should start at the
full amount you borrowed.
For the figures above, the loan payment formula would look like:
0.06 divided by 12 = 0.005 (Monthly Interest Rate)
0.005 x $20,000 = $100 (Monthly Interest Amount)

That $100 will be the interest paid in the first month. However, as you continue to
pay
your loan off, more of your payment goes toward the principal balance and less
toward
interest. Display each month’s interest payment by doing the same math shown
above
using your new, lower loan balance.
Write a python program that lets the user enter the loan amount, APR
and loan period
in number of years and displays the monthly and total payments for first year
alone.
Hint: To calculate a monthly interest rate, divide the annual rate by 12 to reflect
the 12 months
in the year.
While calculating the Monthly payment, kindly ensure the decimal places to be at
least 5
precisions. If so, then you will get the following output.
Here is a sample run:
Paying off an amortizing loan

Paid Paid New


Starting Monthly toward toward loan
loan balance payment princip interes balanc
al t e

$19,713
Month 1 $20,000 $386.66 $286.66 $100.00
.34

$386.6 $19,425.
Month 2 $19,713.34 $288.09 $98.57
6 25

$386.6 $19,135.
Month 3 $19,425.25 $289.53 $97.13
6 72

$386.6 $18,844.
Month 4 $19,135.72 $290.98 $95.68
6 75

$386.6 $18,552.
Month 5 $18,844.75 $292.43 $94.22
6 32

$386.6 $18,258.
Month 6 $18,552.32 $293.89 $92.76
6 42

$386.6 $17,963.
Month 7 $18,258.42 $295.36 $91.29
6 06

Month 8 $17,963.06 $386.6 $296.84 $89.82 $17,666.


6 22

$386.6 $17,367.
Month 9 $17,666.22 $298.32 $88.33
6 89

Month $386.6 $17,068.


$17,367.89 $299.82 $86.84
10 6 07

Month $386.6 $16,766.


$17,068.07 $301.32 $85.34
11 6 76

Month $386.6 $16,463.


$16,766.76 $302.82 $83.83
12 6 9

loanAmount = eval(input("Enter loan amount: "))

apr = eval(input("Enter Annual Percentage Rate(APR): "))

loanPeriod = eval(input("Enter loan period in years: "))

monthlyInterestRate = (apr/100) / 12

monthlyPayment = (loanAmount * monthlyInterestRate) / (1 -


(1/((1+monthlyInterestRate)**(loanPeriod*12))))

print(8 * " " + "Loan balance Monthly Payment Paid toward Principal Paid
toward interest New loan balance")

for i in range(12):

monthlyInterestAmount = loanAmount * monthlyInterestRate

paidTowardPrincipal = monthlyPayment - monthlyInterestAmount


print("Month {:2}{:^15.2f}{:^15.2f}{:^22.2f}{:^27.2f}{:^18.2f}".format(i+1,
loanAmount, monthlyPayment, paidTowardPrincipal, monthlyInterestAmount,
loanAmount - paidTowardPrincipal))

loanAmount -= paidTowardPrincipal

totalPayment = monthlyPayment * 12

print("\nTotal payment (for one year):", round(totalPayment, 2))

print("Total payment:", round(totalPayment*loanPeriod, 2))

Output:

Enter loan amount: 200000

Enter Annual Percentage Rate(APR): 6

Enter loan period in years: 5

Loan balance Monthly Payment Paid toward Principal Paid toward interest
New loan balance

Month 1 200000.00 3866.56 2866.56 1000.00


197133.44

Month 2 197133.44 3866.56 2880.89 985.67


194252.55

Month 3 194252.55 3866.56 2895.30 971.26


191357.25
Month 4 191357.25 3866.56 2909.77 956.79
188447.47

Month 5 188447.47 3866.56 2924.32 942.24


185523.15

Month 6 185523.15 3866.56 2938.94 927.62


182584.21

Month 7 182584.21 3866.56 2953.64 912.92


179630.57

Month 8 179630.57 3866.56 2968.41 898.15


176662.16

Month 9 176662.16 3866.56 2983.25 883.31


173678.91

Month 10 173678.91 3866.56 2998.17 868.39


170680.75

Month 11 170680.75 3866.56 3013.16 853.40


167667.59

Month 12 167667.59 3866.56 3028.22 838.34


164639.37

Total payment (for one year): 46398.72

Total payment: 231993.62

You might also like