Part of the series

Several example codes

~1 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 square of asterisks (*) of size n × n.
For example, if n = 5, the output will be a 5-row, 5-column grid of stars.


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):
        print('* ' * n)
else:
    print("The number must be between 1 and 80.")

Sample Output for n = 5:


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

Step-by-Step Explanation:

- The user inputs a number n
- The program checks that n is between 1 and 80
- A for loop runs n times to print n rows
- Each row prints '* ' repeated n times


Written & researched by Dr. Shahin Siami