~1 min read • Updated Oct 4, 2025
Program Overview
This Python program reads an even number n from the user and prints a specific pattern made of asterisks.
The pattern consists of a horizontal line of three asterisks at the top and bottom, and a vertical column of single asterisks in between.
Although the prompt requests an even number, the sample shown uses n = 9, which is odd — so the program accepts any positive integer.
Python Code:
# Read input from user
n = int(input("Enter an even number: "))
# Print top border
print("***")
# Print vertical column
for _ in range(n):
print("*")
# Print bottom border
print("***")
Sample Output (if n = 9):
***
*
*
*
*
*
*
*
*
*
***
Step-by-Step Explanation:
- The program starts by printing three asterisks for the top border
- Then it prints n lines, each containing a single asterisk
- Finally, it prints three asterisks again for the bottom border
- The input is labeled “even” but the logic works for any positive integer
Written & researched by Dr. Shahin Siami