# William M. Farmer and Spencer Smith
# September 28, 2012
#
# This is a solution for Unmarked Assignment 2 (Lab 03).

import math

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) #FV with compound interest
print "A1=", A1
A2 = p #Notice that A2 needs to be intialized to p!

for i in range(1, (n * t) + 1):
    A2 = A2 * (1 + (r/n))
    print "A2=", A2
    
B = p * math.exp(r * t) #FV with continuous compound interest
print "B=", B

D1 = 100 * abs(A1 - A2) / A1 #Relative difference between compound interest values
D2 = 100 * abs(A1 - B) / B #Relative difference between compound and continous compound interest values

print "D1=", D1
print "D2=", D2


# 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 will not occur when n and t are not integers because
# the for loop won't run due to the end point parameter (in the range
# function) not being of integer value.  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







