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.
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...
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....
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.
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns...
Python: Write a function named calc_odd_sum that accepts a positive integer as the argument and returns the sum of all the odd numbers that are less than or equal to the input number. The function should return 0 if the number is not positive. For example, if 15 is passed as argument to the function, the function should return the result of 1+3+5+7+9+11+13+15. If -10 is passes, it shall return 0. You shall run the program test the result at...
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...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT