This Python program reads two numbers, x and y, and calculates the value of the following expression:
z = x² + 1/x + 3y - 5
The expression includes exponentiation, division, multiplication, and addition.
# Read inputs from user
x = float(input("Enter value for x: "))
y = float(input("Enter value for y: "))
# Calculate z
z = x**2 + 1/x + 3*y - 5
# Display result
print("\n--- Result ---")
print(f"The value of z is: {z:.4f}")
Enter value for x: 2
Enter value for y: 4
--- Result ---
The value of z is: 17.5000
- Inputs are received as floating-point numbers
- x**2 calculates the square of x
- 1/x performs division
- 3*y multiplies y by 3
- All components are added together, and 5 is subtracted
- The result is printed with four decimal places