According to the x value entered using the formula below Write the code of the program that calculates the value of y.
1
---------------
1
x + ----------
1
x + ------
1
x + ---
2
For example:
If x = 1, y = 0.6000000000000001
If x = 10 y = 0.09901951266867294
If x = 100 y = 0.009999000199950014
If x = -5 y = -0.19258202567760344
My code
x = float(input("x= "))
y = (1.0/(x+(1.0/(x+(1.0/(x+0.5))))))
print(y)
My result
x= 1 y= 0.625
x= 10 y= 0.09901914992993928
x= 100 y= 0.009999000199462694
x= -5 y= -0.19262295081967212
I don't know where i did wrong. Results are so close.