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.
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....
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.
Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the...
Write a function decimalToBinary(n) that converts a positive decimal integer n to a string representing the corresponding binary number. Do the conversion by repeatedly dividing the number n by 2 using integer division, keepting track of the remainders, until the number is reduced to 0. The remainders written in reverse order form the binary number string. Do integer division of 5 by 2, so that N//2 is 2 with remainder 1. Now divide 2 by 2 to get 1 with...
(In python) Write a function calc_pizza_charge that takes four integer arguments, one for the size (1...
(In python) Write a function calc_pizza_charge that takes four integer arguments, one for the size (1 small, 2 medium, 3 large), one for the number of meat toppings, one for the number of other toppings and another for the quantity of pizzas ordered. It should calculate and return the total due for that pizza order based on the following information: Small pizza base price: $6.50 Medium pizza base price: $9.50 Large pizza base price: $11.50 The base pizza price includes...
Write a function named hasNValues which takes an array and an integer n as arguments. It...
Write a function named hasNValues which takes an array and an integer n as arguments. It returns true if all the elements of the array are one of n different values. If you are writing in Java or C#, the function signature is int hasNValues(int[ ] a, int n) If you are writing in C or C++, the function signature is int hasNValues(int a[ ], int n, int len) where len is the length of a Note that an array...
Write a function, namely shape(s) that takes a positive integer s as the parameter and draws...
Write a function, namely shape(s) that takes a positive integer s as the parameter and draws a square of length s. The square should be filled by a randomized color. Then write another function, that calls the shape function to draw 4 squares as a 2x2 table. Please answer in python.
In Python, write a program to get a positive integer n from keyboard first (your program...
In Python, write a program to get a positive integer n from keyboard first (your program must be able to check the validation of n being positive), and then get n integers from keyboard and store these n integers in a list. Do some processing, and print out average of the elements in the list at end of your program. For example, suppose user enters 3 first (n = 3), which means we get another three integers from the user....
(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:
In Python8.21 Program: Convert to binary. Sections 2.7, 3.8, 5.2. Functions.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 // 2Note: 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.Your program must define and call the following two functions. The function integer_to_reverse_binary() should return...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT