Advertisement
Guest User

Untitled

a guest
Mar 24th, 2017
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. #-----------------------------------------------------
  2. # Program: Bank Deposit Assignment - main line.py
  3. # Author: Lachlan Sutherland
  4. # Date: Feb 10 2017
  5. # Description: Calculates the amount of money saved
  6. # in a bank account after a given period of time
  7. # Inputs: Inputs an initial deposit, an annual
  8. # depost, an annual interest rate, how often
  9. # interest is compunded (ex 4 means quarterly)
  10. # Output: A table shows how much money will be in the
  11. # bank after every interest period. At the end it
  12. # displays the total interest earned.
  13. #-----------------------------------------------------
  14. import locale
  15. #sets LC_ALL to 'en_US' format
  16. locale.setlocale(locale.LC_ALL)
  17. #, 'en_US'
  18. # all outputs in one array
  19. 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: ",
  20. "DEPOSIT DETAILS:", "Initial Deposit of $", " With annual deposits of $", "Annual Interest rates of ", "% compounded ", " Times per year for ", " years.",
  21. "Lachlan's Banking Investment Plan.", "===================================================================="]
  22. # spacing for format
  23. moneyFormat = [" ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ", " ",""]
  24. # setting initial variables
  25. responseCount = 0
  26. interestShow = 0
  27. totalInterest = 0
  28. counter = 0
  29. year = 1
  30. responses = []
  31. # loops for initial five questions
  32. for num in range(0, 5):
  33. # sets the input to response and the appends response onto responses. locale.atof is used to remove '$' thus not crashing the program
  34. response = locale.atof(input(computerOut[responseCount]))
  35. responseCount += 1
  36. responses.append(response)
  37. # sets the compounded and year inputs to int
  38. responses[4] = int(responses[4])
  39. responses[3] = int(responses[3])
  40. startBalance = responses[0]
  41. endBalance = responses[0]
  42. # simple math to calculate interest
  43. interest = responses[2] / responses[3]
  44. interest /= 100
  45. # startBalanceSpace and endBalanceSpace are used to format to final output, we'd not looked at string formatting yet...
  46. startBalanceSpace = len(str(locale.currency(startBalance, grouping=True)))
  47. endBalanceSpace = len(str(startBalance))
  48. years = input("Do you want the output to be paged by year? (y) or (n)")
  49. print("\n", computerOut[5], "\n", computerOut[6] , "%.2f" % round(responses[0], 2), computerOut[7], "%.2f" % round(responses[1], 2), "\n", computerOut[8],
  50. responses[2], computerOut[9], responses[3], computerOut[10], responses[4], computerOut[11],"\n", "\n", computerOut[12], sep="")
  51. if(years == "y"):
  52. years = responses[4]
  53. if(years == "n"):
  54. years = 1
  55. # this will loop for 0 to years, depending on if paging by year was used.
  56. for x in range(0, years):
  57. # If paging by year was not used then I'd not want it to print year unless it was greater then 1
  58. if(year > 1):
  59. print("Year:", year)
  60. print( "\n", "--------------------------------------------------------------------", sep="")
  61. print(" INT START INTEREST FINAL\n PERIOD BALANCE EARNED BALANCE")
  62. print(computerOut[13])
  63. # loops for each year
  64. for num in range(years, responses[4] + 1):
  65. # loops for each compound
  66. for num in range(0, responses[3]):
  67. counter += 1
  68. # adds and rounds values
  69. startBalance = endBalance
  70. interestShow = round(startBalance * interest, 2)
  71. # this is to check if the len of the interest has increased
  72. if counter == 1:
  73. interestShowSpace = len(str(locale.currency(interestShow, grouping=True)))
  74. totalInterest += round(interestShow, 2)
  75. endBalance += round(startBalance * interest, 2)
  76. 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="")
  77. endBalance += responses[1]
  78. year += 1
  79. if(year != responses[4] + 1):
  80. if(years > 1):
  81. print(computerOut[13])
  82. print("\n", "Total Interest Earned $", "%.2f" % round(totalInterest, 2), sep= "")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement