Skip to content

Instantly share code, notes, and snippets.

@kebman
Created August 2, 2019 03:05
Show Gist options
  • Save kebman/913ae6febe1fa9eb0a58bd608d7b704d to your computer and use it in GitHub Desktop.
Save kebman/913ae6febe1fa9eb0a58bd608d7b704d to your computer and use it in GitHub Desktop.
Calculate compounding interest with this short Python script.
#!/usr/local/bin/python3.7
principal = 10000.0
interest_rate = 5.0
time_units = 10
def get_percentage(inputf, percentage):
return inputf * percentage / 100.0
def get_compounding(principalf, n):
for i in range(0, n):
principalf = principalf + get_percentage(principalf, interest_rate)
print('#%d. $%.2f' % (i + 1, principalf))
# print (principalf)
get_compounding(principal, time_units)
'''
# This is the 'mechanical' way of doing it.
# For the interested, the mathematical formula is: amount = principal(1 + interest_rate / time_units)^(n * time)
'''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment