Skip to content

Instantly share code, notes, and snippets.

@MarketaP
Created January 15, 2019 16:14
Show Gist options
  • Save MarketaP/2a071724319f5d68a8c5683372fdd41f to your computer and use it in GitHub Desktop.
Save MarketaP/2a071724319f5d68a8c5683372fdd41f to your computer and use it in GitHub Desktop.
def loan(principle, annual_percentage_rate, payments_per_year, years):
'''This function calculates monthly payment for a loan'''
monthly_interest = annual_percentage_rate / payments_per_year / 100.0
total_num_payments = yeras * payments_per_year
val = (1 + monthly_interest) ** total_num_payments
return round((principle * monthly_interest * val / (val - 1)), 2)
loan1 = loan(
years = 5.0,
principle = 13000.0,
payments_per_year = 12.0,
annual_percentage_rate = 4.0
)
print(loan1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment