I am very new to python. I have just recently started doing computer science. I am however stuck on this topic as to how do I get the value of the continued fraction of e
constant after I've input a number. Please do not solve it for me but teach me how to go about it. I am not sure if I should use while loops or for loops and even if I do, I am not sure how to go about it.
This is the full phrasing,
One can use the following code in python2.
A copy+paste into the ipython interpreter gave me:
I hope it is clear where python looses precision.
Note that one can also perform exact computations, e.g. by using a fraction supporting package. In such situations i use sage instead of python. Same language, but with more "batteries". The similar version of the code, where we do not start with the float
a = 1. + n
, but with the sage integera = 1+n
gives the fractions. Here is the exact computation, with the a posteriori taken numerical value.Results, that reflect better the periodicity of the decimal representation of rational numbers...
Note: Please show next time the own efforts to compute