Part of the series

Several example codes

~2 min read • Updated Oct 5, 2025

Program Overview

This Python program reads an integer n between 1 and 80 from the user and prints a hollow square of asterisks (*) of size n × n.
Only the four borders of the square are visible — the top, bottom, left, and right edges — while the inside remains empty.


Python Code:


# Read n from user
n = int(input("Enter a number between 1 and 80: "))

# Validate input
if 1 <= n <= 80:
    for i in range(n):
        if i == 0 or i == n - 1:
            print('*' * n)
        else:
            print('*' + ' ' * (n - 2) + '*')
else:
    print("The number must be between 1 and 80.")

Sample Output for n = 10:


**********
*        *
*        *
*        *
*        *
*        *
*        *
*        *
*        *
**********

Step-by-Step Explanation:

- The user inputs a number n
- The program checks that n is between 1 and 80
- The first and last rows are printed as full lines of asterisks
- The middle rows start and end with asterisks, with spaces in between


Written & researched by Dr. Shahin Siami