"""File: cpd_int2.py Purpose: Compute the amount of a principal given an interest rate, the time in years, and the number of periods per year Run: python cpd_int.py Input: Principal (decimal fraction) Interest rate (decimal fraction) Time in years (decimal fraction) Periods per year (whole number) Output: The amount """ #---------------------------------------------------------------------- def cpd_int(P, r, t, y): """ Find the amount of a principal P invested for t years at interest rate r and compounded y times per year. """ n = t*y s = r/y A = P*(1+s)**n return A #---------------------------------------------------------------------- # Program starts executing here P = float(raw_input("Enter the principal\n")) r = float(raw_input("Enter the interest rate (decimal fraction)\n")) t = float(raw_input("Enter the number of years (decimal fraction)\n")) y = int(raw_input("Enter the number of periods per year (whole number)\n")) A = cpd_int(P, r, t, y) print "If", "$%.2f" %P, "is invested for", t, "years at interest" print " rate", r, "(per year), and compounded", y, "times per year," print " then the amount will be", "$%.2f"%A