This Python program evaluates the function Y(x) = x³ - 3x² + 6 for a range of integer and decimal values of x.
It uses two variables with the same name x—one in the loop and one inside the function definition.
def Y(x: float) -> float:
return x**3 - 3*x**2 + 6
print("Y(x) values for x = 1 to 10 (integers):")
for x in range(1, 11):
print(f"Y({x}) = {Y(x)}")
print("\nY(x) values for x = 1.5 to 5.5 (decimals):")
for x in [1.5, 2.5, 3.5, 4.5, 5.5]:
print(f"Y({x}) = {Y(x)}")
Y(1) = 4
Y(2) = 2
Y(3) = 6
Y(4) = 22
...
Y(1.5) = 3.375
Y(2.5) = 3.875
...