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 and prints the '*' character in each line using a loop.
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_stars(n):
    for _ in range(n):
        print("*")

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

Sample Output (input: 5):


*
*
*
*
*

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, a single asterisk '*' is printed on a new line


Written & researched by Dr. Shahin Siami