This Python program receives a numeric input x from the user and evaluates the rational expression:
y = 1 / (x² + x + 1)
This is a useful exercise for practicing algebraic evaluation and handling floating-point precision.
# Get input from user
x = float(input("Enter the value of x: "))
# Calculate the expression
denominator = x**2 + x + 1
y = 1 / denominator
# Display result
print("\n--- Result ---")
print("y = 1 / (x² + x + 1) =", y)
Enter the value of x: 2
--- Result ---
y = 1 / (x² + x + 1) = 0.2
- The input x is received using input() and converted to a float
- The denominator x² + x + 1 is computed using x**2 for exponentiation
- The final result y is calculated and printed with full precision
- You can round the result or format it as needed for display