Hi,

The subject of this task is to display to the user an approximation of e.

When a user give you a precision for example 2, you have to display e and to be sure that the two first numbers just after the coma are right.

To check your result you can use the google approximation.

I created two function:

The first one « is_equal » function is to respect this point of the subject: You will want to use the infinite series to calculate the value, stopping when the accuracy is reached (previous and current calculation are the same at the specified accuracy).

Be careful you use precision+1 because we want that the number is truncated  and the round function modify the result.

The second function reproduced the wikipedia sum formula with factorial.

Don’t forget to import the math module !

I initialized in this way :

e_previous = -1 -> we don’t care because the e_previous = 0 in the first iteration
e_current = 0 -> to respect the formula in the first iteration of the while loop
i = 0 -> to respect the formula 0! = 1 so e_current = 1 (the first value of the sum)

Here is my code:

https://github.com/aureliemartinet/TC101/blob/master/wsq14.py

Have a good day !

 

 

 

CC BY 4.0 WSQ14 #TC101 by aureliemartinette is licensed under a Creative Commons Attribution 4.0 International License.