This project will give you experience with writing functions, as well as using looping.
Write a Python program (call it 'e.py') by completing the following:
factorial(n)that returns the factorial of a number. Recall that a factorial is defined as n! = 1 x 2 x 3 x .... x (n-1) x n.
e(n)that approximates the value of the number e. The value e (Euler's number, the base of the natural logarithm) is defined using an infinite sum as e = 1 + (1/(1!)) + (1/(2!)) + (1/(3!)) + ... . The parameter for the function represents how many terms to include from the series (the more terms you add, the more accurate the number becomes). For example, calling e(4) should return the value 1 + (1/1) + (1/2) + (1/6) ≈ 2.667. You should make use of the factorial function from the previous step.
main()function that asks the user for the number of terms to use for the approximation of the number e, then calls the
e()function you wrote.
main(), compare the value you computed to the value stored in the math library (math.e). Compare them by computing the absolute error, which can be computed by taking the absolute value of (yourComputedValue - math.e).
Your program output should match the following exactly (note that some of it is user input that will not be known until the program runs):
The e Approximation Program How many terms do you want to use for the approximation: 3 The approximated value of e is 2.5, which has an error of 0.2182818284590451 .
To submit, save your Python program in a file named 'e.py', and submit it to Moodle by the due date.