Question
Asking Python Imagine that you get paid on the 1st and 15 th of the month. After looking at your budget, you feel you could
Asking Python
Imagine that you get paid on the 1st and 15th of the month. After looking at your budget, you feel you could spend $200 a paycheck and you are thinking of buying a car. You know the interest rate will be 4.74%. You figure the car loan will be spread over 4 years, paying 2 payments per month (24 a year). The care you are looking at is $20,000. Can you afford it?
There is a financial formula out there you could use.
With this formula, you would need to understand what the variables are.
- PMT = Payment per period
- PV = Present Value you are borrowing
- FV = Future Value you want (which is likely 0!)
- N = Number of Payments a year (24 twice a month)
- ip = interest rate (4.74%) per period
- k = 1 if payment is made at the end of the period (Trust me its a financial thing)
Lets use Pythons shell to see if we can afford the car? Here I am using the interpreter and commands.
Python 3.9.1 (tags/v3.9.1:1e5d33e, Dec 7 2020, 17:08:21) [MSC v.1927 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> PV= 20000
>>> i = 4.74
>>> NumYrs = 4
>>> PmtPerYear = 24 #2 payments per month
>>> FV = 0 # Future Value of loan is $0. (You want this paid off, right?)
>>> k = 1 # (payment is at end of period ... it's a finance thing!)
>>>
>>> ## Now ... off to calculate payment. This will look messy.
>>>
>>> numerator = PV + FV
>>> ip = i/100/PmtPerYear
>>> NumPmts = NumYrs * PmtPerYear
>>> denominator = (1 + ip)**NumPmts - 1
>>> fraction = numerator/denominator
>>> other_fraction = (-1 * ip/k)
>>> Payment = PV + fraction
>>> Payment = Payment * other_fraction
>>>
>>> Payment
-228.91210686170604
>>>
So, the payments would be $-228.91, twice a month! Why negative? Because you are paying DOWN a loan. If you were INVESTING, it would be positive.
But, to take the guess work out, why dont we just put the payment into a FUNCTION that gives us the Absolute Value (always positive) and then print it out, using a format function!
>>> abs(Payment)
228.91210686170604
>>> print(f"Your payment would be ${abs(Payment):,.2f} a period")
Your payment would be $228.91 a period
So, how much did you totally spend on your car? (The number of payments multiplied by the payments)
>>> totalCost = abs(Payment) * NumPmts
>>> print(f"Your Total Cost of the car would be ${totalCost:,.2f}")
Your Total Cost of the car would be $21,975.56
How much interest? (What is the cost of borrowing??)
>>> costOfBorrowing = totalCost - PV
>>> print(f"The cost of borrowing would be ${costOfBorrowing:,.2f}")
The cost of borrowing would be $1,975.56
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