Calcuter
def mortgage_calculator(principal, interest, years):
"""
Calculates the monthly mortgage payment based on principal, interest, and years.
:param principal: The total amount of the loan (in dollars)
:param interest: The annual interest rate (as a decimal)
:param years: The number of years the loan will be paid over
:return: The monthly mortgage payment (in dollars)
"""
# Convert the annual interest rate to a monthly interest rate
monthly_interest_rate = interest / 12
# Calculate the number of monthly payments
num_payments = years * 12
# Calculate the monthly mortgage payment
monthly_payment = principal * (monthly_interest_rate / (1 - (1 + monthly_interest_rate)**(-num_payments)))
return monthly_payment
Comments
Post a Comment