Part of the series

Several example codes

~1 min read • Updated Sep 28, 2025

Program Overview

This Python program receives an integer n from the user and calculates the result of the expression n + n × n.
This is a simple exercise that reinforces operator precedence in Python, where multiplication is evaluated before addition.


Python Code:


# Get an integer from the user
n = int(input("Enter an integer: "))

# Calculate the expression
result = n + n * n

# Display the result
print("\n--- Result ---")
print("n + n × n =", result)

Sample Output:


Enter an integer: 3  
--- Result ---  
n + n × n = 12

Explanation:

- The input n is received using input() and converted to an integer
- The expression n + n × n is evaluated using Python’s operator precedence rules
- The result is printed using print() with clear labeling


Written & researched by Dr. Shahin Siami