Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Bank Interest Calculator as a new project #377

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Bank_Interest_Calculator/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Bank Interest Calculator

Simple Text-based interest calculator

### What can I do with it?:
- Calculate the interest amount
- Calculate the total amount including the interest
#### for the specified amount of years.

### How can I run it?
#### You can run it via:
- terminal or command prompt
- any IDE that supports Python
62 changes: 62 additions & 0 deletions Bank_Interest_Calculator/interest_calculator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
running = True


def program(choice):
years = int(input('How many years are you going to save? >> '))
amount = int(input('How much are you saving yearly? >> '))
r = input('What is the interest rate per year? (eg: 10, 0.1) >> ')
try:
rate = int(r)
except ValueError:
rate = float(r)
new_amount = 0
balance = 0
total = 0
interest = 0
n = 0

if choice.lower() == 'i':
for i in range(0, int(years)):
n += 1
if type(rate) is float:
interest += amount * rate
elif type(rate) is int:
interest += amount * (rate / 100)

print(f"In year {n}, the interest earned will be ${interest}")
total += interest
print(f'By the end of year {n}, the total interest earned will be ${total}.')

elif choice.lower() == 't':
for i in range(0, int(years)):
n += 1
if type(rate) is float:
if balance == 0:
interest = amount * rate
balance = amount + interest
elif balance > 0:
old_balance = balance
interest = (old_balance + amount) * rate
balance = old_balance + amount + interest
elif type(rate) is int:
if balance == 0:
interest = amount * (rate / 100)
balance = amount + interest
elif balance > 0:
old_balance = balance
interest = (old_balance + amount) * (rate / 100)
balance = old_balance + amount + interest

print(f"In year {n}, your total balance will be ${round(balance, 2)}")
print(f'By the end of year {n}, your total balance will be {round(balance, 2)}.')


while running:
print(
"How would you like to be calculated?\n'I' for total interest amount\n'T' for total balance including interest "
"amount\n'E' to exit program")
user_choice = input("Method >> ")
if user_choice.lower() == 'e':
running = False
else:
program(user_choice)
Loading