# William M. Farmer and Spencer Smith
# Revised September 19, 2011
#
# This is a solution for Minor Assignment 1 (Lab 01).

print "This program illustrates the convergence of (1 + 1/n)^n to e as n increases."
x = input("Enter an integer greater than or equal to 1: ")
print "The following are the first", x, "approximations of e:"
for n in range(1, x+1):
    print "The", n , "th term is = " , (1 + (1.0/n)) ** n


# Design Question
# 
# If the user enters an integer less than 1, the program prints nothing.
# Ideally, the program should tell the user that the integer entered is
# out of range and ask the user again to enter an integer greater than
# or equal to 1.
# 
# Testing Question
# 
# A good way to test that the program is calculating the steps correctly
# is to calculate the expected value of (1 + 1/x)^x and compare it to
# the last value printed by the program.  A quick test of the program is
# to see whether the values printed by the program are converging to the
# value of e. A sample test report is provided below, where the input is the 
# integer that is input and the expected output is the value for the 
# approximation of e for this value.  The actual output is the final value
# calculated by the program.  The comment says whether the the actual
# and expected output are equal.
# 
# Input	Expected Output   	Actual Output   	Comments
# ---------------------------------------------------------------------
# 1	2.0			2.0			Pass
# 2	2.25			2.25			Pass
# 3	2.37037037037		2.37037037037		Pass
# 10	2.5937424601 		2.5937424601		Pass
# 100	2.70481382942		2.70481382942		Pass
# 
# Extra Study Question
# 
# No, the program does not provide a good way to approximate e.  Even
# for a large x, the approximation is not very close to e.  For instance,
# for x = 1000, the approximation is 2.71692393224, but the true value
# of e is 2.7182818284590451.  The approximation is thus only correct to
# 3 digits.  An overview of some faster algorithms to calculate the
# exponential function (exp(1) = e) is found at
# 
#   http://www.convict.lu/Jeunes/ultimate_stuff/exp_ln_2.htm

#*******************************************************************************
#SOLUTIONS TO EXTRA PRACTICE
#*******************************************************************************
"""
import math
print "\n\nSolutions to Extra Practice"

#exp1 = 0.5sin(pi/2)+1.6cos(3pi/4)
exp1= 0.5*math.sin(math.pi/2)+1.6*math.cos(3.0*math.pi/4.0)
print "exp1 = 0.5sin(pi/2)+1.6cos(3pi/4) =", exp1

#exp2 = e^(-4.5^2)+ln(0.87)
exp2= math.exp(-4.5**2)+math.log(0.87)
print "exp2 = e^(-4.5^2)+ln(0.87) =", exp2

#exp3 = 1.453 x10^-12 xsqrt(2.5 x10^6)
exp3= 1.453E-12*math.sqrt(2.5E6)
print "exp3 = 1.453 x10^-12 xsqrt(2.5 x10^6) =", exp3

#exp4 = atan(0.8)
exp4= math.atan(0.8)
print "exp4 = atan(0.8) =", exp4

#exp5 = (4pi/3)x0.74^3
exp5= (4.0*math.pi/3.0)*math.pow(0.74, 3)
print "exp5 = (4pi/3)x0.74^3 =", exp5
"""
