Part of the series

Several example codes

~1 min read β€’ Updated Oct 12, 2025

Program Overview

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.


Python Code:


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)}")

Sample Output:


Y(1) = 4  
Y(2) = 2  
Y(3) = 6  
Y(4) = 22  
...
Y(1.5) = 3.375  
Y(2.5) = 3.875  
...

Written & researched by Dr. Shahin Siami