# # A simple loan payment calculator for a car loan # # # Read amount borrowed, annual interest rate and repayment time (in years) # amount_borrowed = input("How much are you going to borrow? ") interest_rate = input("Enter the interest rate per year (5% as 0.05): ") years = input("Enter the number of years to repay the loan: ") # # Get the values entered by the user into the form expected by the # equation. Repayment period needs to be in number of payments, and # interest rate needs to be per payment, not per year. As a result # we need to multiply / divide by 12 for monthly payments. # monthly_rate = interest_rate / 12.0 num_payments = years * 12 # # Compute the payment amount # payment_amount = (monthly_rate * amount_borrowed) / (1 - (1 + monthly_rate) ** -num_payments) # # Display the result, formatting it to two decimal places # print "Your monthly payment will be",("%.2f" % payment_amount) print "The total cost of borrowing was",("%.2f" % (payment_amount * num_payments - amount_borrowed))