Question

In: Computer Science

I have a python coding question: Write the function: eAapproximately (n), that takes a positive integer...

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?

Solutions

Expert Solution

#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))


Related Solutions

Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns,...
Write, in Python, a recursive algorithm that takes, as input, a positive integer n, and returns, as output, the sum of the first n positive odd integers. Your solution should be recursive, and it should not contain any "for" loops or "while" loops.
Write a function in python that takes in an integer n and computes the left hand...
Write a function in python that takes in an integer n and computes the left hand Riemann sum of the function f(x) = x^2 on the interval [0,1]. Hint: compute the error from the true answer
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the...
python exercise: a. Write a function sumDigits that takes a positive integer value and returns the total sum of the digits in the integers from 1 to that number inclusive. b. Write a program to input an integer n and call the above function in part a if n is positive, else give ‘Value must be Positive’ message. sample: Enter a positive integer: 1000000 The sum of the digits in the number from 1 to 1000000 is 27000001 Enter a...
Write a Scheme function that takes a positive integer n and returns the list of all...
Write a Scheme function that takes a positive integer n and returns the list of all first n positive integers in decreasing order: (decreasing-numbers 10) (10 9 8 7 6 5 4 3 2 1) Please explain every step
IN PYTHON Write a program that takes in a positive integer as input, and outputs a...
IN PYTHON Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string....
I am coding with NetBeans LDE Java. Write a program that reads a positive integer n...
I am coding with NetBeans LDE Java. Write a program that reads a positive integer n , prints all sums from 1 to any integer m 1≤m≤n . For example, if n=100, the output of your program should be The sum of positive integers from 1 to 1 is 1;       The sum of positive integers from 1 to 2 is 3;       The sum of positive integers from 1 to 3 is 6;       The sum of positive integers...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie...
Write a Python function next_Sophie_Germain(n), which on input a positive integer n return the smallest Sophie Germain prime that is greater or equal to n.
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns...
PYTHON 3: Write a recursive function that takes a non-negative integer n as input and returns the number of 1's in the binary representation of n. Use the fact that this is equal to the number of 1's in the representation of n//2 (integer division) plus 1 if n is odd. >>>numOnes(0) 0 >>>numOnes(1) 1 >>>numOnes(14) 3
In R studio Write a function that takes as an input a positive integer and uses...
In R studio Write a function that takes as an input a positive integer and uses the print() function to print out all the numbers less than the input integer. (Example: for input 5, the function should print the numbers 1,2,3,4 { for input 1, the function should not print a number.) Use the lapply function, do not use any of the loop commands in your code.
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and...
C++ 1. Write a function decimalToBinary() that takes in a positive integer as a parameter and use as stack to convert the integer to a its corresponding binary representation. Hint: divide the integer by 2. 2. A palindrome is a string of characters (a word, phrase, or sentence) that is the same regardless of whether you read it forward or backward—assuming that you ignore spaces, punctuation, and case. For example, Race car is a palindrome. So is A man, a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT