Add interest.py

This commit is contained in:
SileNce5k 2023-07-05 07:19:09 +02:00
parent 4c4ad2cd9c
commit 117ab9b1c7
No known key found for this signature in database
GPG key ID: C507260E7F2583AD
2 changed files with 32 additions and 1 deletions

1
.gitignore vendored
View file

@ -1 +1,2 @@
data/
interest_report.md

30
interest.py Normal file
View file

@ -0,0 +1,30 @@
def calculate_interest():
years = int(input("How many years do you want to invest? "))
monthly_investment = float(input("How much money will you invest each month? "))
interest_rate = float(input("What is the annual interest rate (in percentage)? ")) / 100
currency = input("What is the currency? ")
is_currency_before = input("Is the currency symbol/word before the value? (yes/no) ") == 'yes'
thousands_sep = input("What thousands separator would you like to use? ")
money = 0.0
interest_per_month = interest_rate / 12
md_table = "| Year | Month | Money gained from Interest | Total Money |\n|------|-------|---------------------------|-------------|\n"
for year in range(1, years + 1):
for month in range(1, 13):
gained_interest = money * interest_per_month
money += gained_interest + monthly_investment
money_string = f"{currency}{format(money, ',.2f').replace(',', thousands_sep)}" if is_currency_before else f"{format(money, ',.2f').replace(',', thousands_sep)}{currency}"
gained_interest_string = f"{currency}{format(gained_interest, ',.2f').replace(',', thousands_sep)}" if is_currency_before else f"{format(gained_interest, ',.2f').replace(',', thousands_sep)}{currency}"
md_table += f"| {year} | {month} | {gained_interest_string} | {money_string} |\n"
with open("interest_report.md", "w") as file:
file.write(md_table)
return md_table
print(calculate_interest())