Part of the series

Several example codes

~1 min read • Updated Sep 29, 2025

Program Overview

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.


Python Code:


# 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)

Sample Output:


Enter the value of x: 2  
--- Result ---  
y = 1 / (x² + x + 1) = 0.2

Explanation:

- 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


Written & researched by Dr. Shahin Siami