# # Program: interest.py # Author: James Tam # Version: February 15, 2013 # A simple interest calculator (it won't work for compound or interest on # on interest calculations). # Learning concepts: # 1) Return values # function: introduction # @introduction(none) # @returns(nothing) # Describes how the program works to the user. def introduction(): print(""" Simple interest calculator ------------------------------- With given values for the principle, rate and time period this program will calculate the interest accrued as well as the new amount (principle plus interest). """) # function: getInputs # @getInputs(none) # @returns(float,float,int) # Prompt the user for the inputs to the operation: principle, rate, time # These values must be returned back to the caller of this function so # they can be used to derive interest and the amount. def getInputs (): principle = float(input("Enter the original principle: ")) rate = float(input("Enter the yearly interest rate %")) rate = rate / 100.0 time = int(input("Enter the number of years that money will be invested: ")) return(principle, rate, time) # function: calculate # @calculate(float,float,int) # @returns(float,float) # Based on the values entered by the user for the principle, rate and time # this function will calculate the interest earned as well as the new # amount in the user's bank account. # Precondition: Principle, rate, time have been set to meaningful values. def calculate(principle, rate, time): interest = principle * rate * time amount = principle + interest return(interest,amount) # function: display # @fun(float,float,int,float,float) # @returns(nothing) # Shows but doesn't modify the results of the calculation (amount and interest) # as well as the original inputs to the operation (principle, rate, time). def display (principle, rate, time, interest, amount): temp = rate * 100 print("") print("With an investment of $", principle, " at a rate of", temp, "%", end="") print(" over", time, " years...") print("Interest accrued $", interest) print("Amount in your account $", amount) # @start(none) # @returns(nothing) def start(): principle = 0 rate = 0 time = 0 interest = 0 amount = 0 introduction () principle,rate,time = getInputs () interest,amount = calculate (principle, rate, time) display (principle, rate, time, interest, amount) start()