Part of the series

Several example codes

~1 min read • Updated Oct 11, 2025

Program Overview

This Python program reads an integer from the user, representing the number of lines.
Using a loop, it prints the characters 'X' and '*' in each line.
This exercise helps practice basic loop structures and multi-character output formatting.


Python Code:


def print_x_and_star(lines):
    for i in range(lines):
        print("X *")

# Run the program
lines = int(input("Enter number of lines: "))
print_x_and_star(lines)

Sample Output (input: 3):


X *
X *
X *

Step-by-Step Explanation:

- The program first reads the number of lines from the user
- A for loop runs for that many iterations
- In each iteration, it prints the string "X *" on a new line
- The result is a vertical list of lines, each containing the characters 'X' and '*'


Written & researched by Dr. Shahin Siami