# # Compute the payment amount and cost of borrowing for a loan based on the # amount borrowed, interest rate, and loan duration (amortization period). # # Read the amount borrowed, interest rate, and loan duration from the user. amount = float(input("Enter the amount for the loan: ")) rate = float(input("Enter the interest rate (5 for 5%): ")) duration = int(input("Enter the loan duration in years: ")) # Convert the interest rate to a decimal rate = rate / 100 # Convert from an annual interest rate to a rate per payment period. rate = rate / 12 # Compute the number of payments num_payments = duration * 12 # Compute the payment amount for the loan. payment = rate * amount / (1 - (1 + rate) ** -num_payments) # Compute the cost of borrowing. cost_of_borrowing = payment * num_payments - amount # Display the results. print(f"Your monthly payment is ${payment:,.2f}.") print(f"The total cost of borrowing is ${cost_of_borrowing:,.2f}.")