~1 min read • Updated Oct 11, 2025
Program Overview
This Python program reads an integer from the user and prints the string "* 1" in each line using a loop.
The number of lines is determined by the input value.
This exercise helps reinforce basic loop structures and string formatting in terminal output.
Python Code:
def print_star_one(n):
for i in range(n):
print("* 1")
# Run the program
rows = int(input("Enter number of rows: "))
print_star_one(rows)
Sample Output (input: 3):
* 1
* 1
* 1
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 string "* 1" is printed on a new line
- This output combines a symbol and a number, useful for practicing loop-based string printing
Written & researched by Dr. Shahin Siami