In: Computer Science
I have a python coding question:
Write the function: eAapproximately (n), that takes a positive integer value n and returns an approximation of e as (1 + 1/n)^n
I am not even sure what the question is asking me to do but I think it is asking me to code that function. Does anyone know how to do this?
#python code please do care of indentation
#save code 'xyz.py'
#run 'python xyz.py'
#for explanation see screenshots added
#########################################################################
#   eApproximation(n):   takes positive no. as
n           #
#       calculate the value of given
formula           #
#       (1 + 1/n)^n as an approximation of
e           #
#          
           
            #
#   if you see that what is e?  
           
    #
#       The number e is a famous
irrational number, and is one #
#       of the important numbers in
mathematics.       #
#       The first few digits
are:          
    #
#          
2.7182818284590452353602874713527      
#
#       It is often called Euler's
number           #
#          
           
            #
#   Basically this question is asking that use that given
formula   #
#   and calculate the approximation of 'e'.  
            #
#   If you increase the value of n than this formula
gives better   #
#   approximation of e.      
           
    #
#          
           
            #
#          
           
            #
#   lim[n->infinity](1 + 1/n)^n = e  
           
    #
#          
           
            #
#   if the value of n->infinity then formula gives
exact value of   #
#   e. Here we need to write a python code which will
calculate   #
#   the value of e using that formula.  
            #
#   for further explanation see the screen shot
added       #
#########################################################################
def eApproximation(n):
   x = float(n)
   e = (1 + 1/x)**x
   return e
print("(n, e)")
for i in [1,2,5,10,100,1000,10000,100000]:
   print(i, eApproximation(i))



