# William M. Farmer and Spencer Smith
# September 30, 2011
#
# This is a solution for Unmarked Assignment 2 (Lab 02).

import math

def main():
    print """\

This program computes the future values of investments with compound
interest and with continuous compound interest and then compares the
difference between them.
"""
    p = input("Enter the initial principal: ")
    r = input("Enter the interest rate: ")
    n = input("Enter the number of times interest is compounded per year: ")
    t = input("Enter the number of years: ")
    a1 = p*(1 + r/n)**(n*t)
    print "\n---------------------------------------------------------------------------------------------"
    print "The future value with compound interest is (using the equation) A1=", a1
    print "\n---------------------------------------------------------------------------------------------"
    a2 = p
    for i in range(1, (n * t) + 1):
        a2 = a2 * (1 + (r/n))
        print "The future value with compound interest is: (using the for loop) A2=", a2
    b = p * math.exp(r * t)
    print "The future value with continuous compound interest is: B=", b
    d1 = 100 * abs(a1 - a2) / a1
    d2 = 100 * abs(a1 - b) / b
    print "\n---------------------------------------------------------------------------------------------"
    print "The relative difference between compound interest values is: D1=", d1, "%"
    print "\n---------------------------------------------------------------------------------------------"
    print "The relative difference between compound and continous compound interest values is: D2=", d2, "%"
    print ""

main()

# Design Question
# 
# The program above does not enforce n and t to be integers.  The
# mathematical formulas work fine when n and t are not integers, but the
# computation of a2 may be incorrect when n and t are not integers.  This
# is because the body of the for loop can only be executed an integral
# numbers of times.  (For example, it is not possible to execute the
# body of a for loop 2.5 times.)
# 
# Testing Question
# 
# Test 1 
# Input: [100, 0.5, 4, 5] 
# Expected Output: [1054.51, 1054.51, 1218.25, 0.0, 13.44] 
# Actual Output: [1054.51, 1054.51, 1218.25, 0.0, 13.44] 
# Result: Pass

# Test 2
# Input: [1000, 0, 1, 1] 
# Expected Output: [1000, 1000, 1000, 0.0, 0] 
# Actual Output: [1000, 1000, 1000, 0.0, 0] 
# Result: Pass






