Skip to content

Instantly share code, notes, and snippets.

@wmucheru
Created August 1, 2022 09:40
Show Gist options
  • Save wmucheru/029fddd735af369a72a0b4d6af923aac to your computer and use it in GitHub Desktop.
Save wmucheru/029fddd735af369a72a0b4d6af923aac to your computer and use it in GitHub Desktop.
# Compound interest: https://www.youtube.com/watch?v=P182Abv3fOk
# A = P(1 + r/n)tN
def compound(principle, interest, time, annual = True):
interest_percent = interest / 100
amount_annual = principle * (1 + interest_percent) ** time
amount_monthly = principle * (1 + (interest_percent / 12)) ** (time * 12)
return amount_annual if annual else amount_monthly
print(f"Annually: {compound(1000, 5, 7)}")
print(f"Monthly: {compound(2000, 12, 5, annual=False)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment