~1 min read • Updated Oct 11, 2025
Program Overview
This Python program reads an integer from the user and uses a for loop to print the character 'x' in each line.
The number of lines is determined by the input value.
This exercise helps reinforce basic loop structures and terminal output formatting in Python.
Python Code:
def print_x_lines(n):
for i in range(n):
print("x")
# Run the program
rows = int(input("Enter number of lines: "))
print_x_lines(rows)
Sample Output (input: 5):
x
x
x
x
x
Step-by-Step Explanation:
- The program first reads an integer from the user
- A for loop runs for the specified number of iterations
- In each iteration, the character 'x' is printed on a new line
Written & researched by Dr. Shahin Siami