# L-4 MCS 260 Wed 5 Sep 2007 yield and balance computation # # This program prompts the user for the following inputs: # (1) principal , (2) annual interest rate (percentage format), # (3) and number of years. (1) and (2) are floats, (3) is integer. # The output of the program consists of # (1) the ending balance and (2) the yield of the investment. # # welcome message, read input and convert to arithmetic types print 'computation of yield and balance' user_input = raw_input('Give the principal : ') principal = float(user_input) user_input = raw_input('Give the annual interest rate : ') interest = float(user_input) user_input = raw_input('Give the number of years : ') years = int(user_input) # confirm the user input using string concatenation confirm_principal = 'Investing ' + '$%.2f' % principal confirm_interest = ' at ' + '%.2f' % interest + '%' confirm_years = ' for ' + '%d' % years + ' years' print confirm_principal + confirm_interest + confirm_years # calculate balance and yield (yield is a Python statement) balance = principal * (1.0 + interest/100.0)**years the_yield = balance - principal # print the outcome, again using string concatenation show_balance = '$%.2f' % balance + ' as balance' show_yield = '$%.2f' % the_yield + ' as yield' print 'gives ' + show_balance + ' and ' + show_yield + '.'