Created
August 1, 2022 09:40
-
-
Save wmucheru/029fddd735af369a72a0b4d6af923aac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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