I have a project i'm working on for school and I'm pretty sure I've got it correct, but i'm not sure how to check the output. I just need an idea of whether or not i'm going about this correctly. The assignment is to have it display the monthly payment and the total interest. Here's my code
principal = float(input("Input Loan Principal: "))
# Principal amount borrowed input by user
loan_term = float(input("Input Loan Term In Years: "))
# Loan Term in years input by user
loan_interest = float(input("Input Loan Interest Rate: "))
# Loan interest in percentage input by user
monthly_rate = loan_interest / 100
# Loan interest percentage to decimal
loan_term_months = loan_term * 12
# Loan term from years to months
balance = principal
# Separate variable for calculations
math1 = (1.0 + monthly_rate) ** loan_term
math2 = (monthly_rate/(math1 - 1.0))
# Calculations
monthly_payment = (monthly_rate + math2) * balance
# Final Calculation for monthly payment
interest = (monthly_payment * loan_term) - principal
# Final Calculation for interest paid
final_monthly_payment = str(round(monthly_payment, 2))
final_interest = str(round(interest, 2))
# Rounding to two decimal points
print("Monthly payment: ", final_monthly_payment)
print("Effective Interest Paid: ", final_interest)
# Final print
Thanks for any help in advance
Here's a fancy way to check your answer using scipy fsolve:
Printing
result
returns:The main concept above is to let scipy solve for the variable
pmt
in the formula... which is the payment amount. Interpretation is that a payment of $1,854.02 would be needed to pay off a $200,000 loan in 15 years at 7.5%.To see how much principal and interest goes towards each payment, numpy again could help you out with
np.ppmt
andnp.ipmt
. Example:Returns: