Calculate math expression like: y=1/x+1/x+1/x+1/x in Python
![Root](https://linuxlife.eu/wp-content/plugins/ultimate-member/assets/img/default_avatar.jpg)
Quote from Root on 11/08/2022, 17:08Hello all!
We need to calculate some math expression like the one in the picture.
how can we do that? Keep reading...Your task is to complete the code in order to evaluate the following expression:
The result should be assigned to y. Be careful - watch the operators and keep their priorities in mind.
Don't hesitate to use as many parentheses as you need.You can use additional variables to shorten the expression (but it's not necessary).
Test your code carefully with some Data:Sample input: 1
Expected output:
y = 0.6000000000000001Sample input: 10
Expected output:
y = 0.09901951266867294Sample input: -5
Expected output:
y = -0.19258202567760344
Here is how we do it:
x = float(input("Enter value for x: "))
y = 1/(x+(1/(x+(1/(x+1/x)))))
print("y =", y)
See attached image if needed
Hello all!
We need to calculate some math expression like the one in the picture.
how can we do that? Keep reading...
Your task is to complete the code in order to evaluate the following expression:
The result should be assigned to y. Be careful - watch the operators and keep their priorities in mind.
Don't hesitate to use as many parentheses as you need.
You can use additional variables to shorten the expression (but it's not necessary).
Test your code carefully with some Data:
Sample input: 1
Expected output:
y = 0.6000000000000001
Sample input: 10
Expected output:
y = 0.09901951266867294
Sample input: -5
Expected output:
y = -0.19258202567760344
Here is how we do it:
x = float(input("Enter value for x: "))
y = 1/(x+(1/(x+(1/(x+1/x)))))
print("y =", y)
See attached image if needed
Uploaded files: