Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #-----------------------------------------------------
- # Program: Bank Deposit Assignment - main line.py
- # Author: Lachlan Sutherland
- # Date: Feb 10 2017
- # Description: Calculates the amount of money saved
- # in a bank account after a given period of time
- # Inputs: Inputs an initial deposit, an annual
- # depost, an annual interest rate, how often
- # interest is compunded (ex 4 means quarterly)
- # Output: A table shows how much money will be in the
- # bank after every interest period. At the end it
- # displays the total interest earned.
- #-----------------------------------------------------
- import locale
- #sets LC_ALL to 'en_US' format
- locale.setlocale(locale.LC_ALL)
- #, 'en_US'
- # all outputs in one array
- computerOut = ["Enter Initial Deposit: ", "Enter Annual Deposit: ", "Enter the Annual Interest Rate: ", "Interest will be compounded how many times per year: ", "Enter the length of the deposit in years: ",
- "DEPOSIT DETAILS:", "Initial Deposit of $", " With annual deposits of $", "Annual Interest rates of ", "% compounded ", " Times per year for ", " years.",
- "Lachlan's Banking Investment Plan.", "===================================================================="]
- # spacing for format
- moneyFormat = [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",""]
- # setting initial variables
- responseCount = 0
- interestShow = 0
- totalInterest = 0
- counter = 0
- year = 1
- responses = []
- # loops for initial five questions
- for num in range(0, 5):
- # sets the input to response and the appends response onto responses. locale.atof is used to remove '$' thus not crashing the program
- response = locale.atof(input(computerOut[responseCount]))
- responseCount += 1
- responses.append(response)
- # sets the compounded and year inputs to int
- responses[4] = int(responses[4])
- responses[3] = int(responses[3])
- startBalance = responses[0]
- endBalance = responses[0]
- # simple math to calculate interest
- interest = responses[2] / responses[3]
- interest /= 100
- # startBalanceSpace and endBalanceSpace are used to format to final output, we'd not looked at string formatting yet...
- startBalanceSpace = len(str(locale.currency(startBalance, grouping=True)))
- endBalanceSpace = len(str(startBalance))
- years = input("Do you want the output to be paged by year? (y) or (n)")
- print("\n", computerOut[5], "\n", computerOut[6] , "%.2f" % round(responses[0], 2), computerOut[7], "%.2f" % round(responses[1], 2), "\n", computerOut[8],
- responses[2], computerOut[9], responses[3], computerOut[10], responses[4], computerOut[11],"\n", "\n", computerOut[12], sep="")
- if(years == "y"):
- years = responses[4]
- if(years == "n"):
- years = 1
- # this will loop for 0 to years, depending on if paging by year was used.
- for x in range(0, years):
- # If paging by year was not used then I'd not want it to print year unless it was greater then 1
- if(year > 1):
- print("Year:", year)
- print( "\n", "--------------------------------------------------------------------", sep="")
- print(" INT START INTEREST FINAL\n PERIOD BALANCE EARNED BALANCE")
- print(computerOut[13])
- # loops for each year
- for num in range(years, responses[4] + 1):
- # loops for each compound
- for num in range(0, responses[3]):
- counter += 1
- # adds and rounds values
- startBalance = endBalance
- interestShow = round(startBalance * interest, 2)
- # this is to check if the len of the interest has increased
- if counter == 1:
- interestShowSpace = len(str(locale.currency(interestShow, grouping=True)))
- totalInterest += round(interestShow, 2)
- endBalance += round(startBalance * interest, 2)
- print(moneyFormat[len(str(counter))], counter, moneyFormat[len(str(locale.currency(startBalance, grouping=True))) - startBalanceSpace], locale.currency(startBalance, grouping=True), moneyFormat[len(str(locale.currency(interestShow, grouping=True))) - interestShowSpace], locale.currency(interestShow, grouping=True), moneyFormat[len(str(locale.currency(endBalance, grouping=True))) - endBalanceSpace], locale.currency(endBalance, grouping=True), sep="")
- endBalance += responses[1]
- year += 1
- if(year != responses[4] + 1):
- if(years > 1):
- print(computerOut[13])
- print("\n", "Total Interest Earned $", "%.2f" % round(totalInterest, 2), sep= "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement