This Python program reads an integer n between 1 and 80 and prints a square pattern of size n × n using asterisks (*).
The output shows only the four borders and the imaginary diagonal — from top-right to bottom-left.
# 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):
row = ''
for j in range(n):
if i == 0 or i == n - 1 or j == 0 or j == n - 1 or i + j == n - 1:
row += '* '
else:
row += ' '
print(row)
else:
print("The number must be between 1 and 80.")
* * * * *
* * * * *
* * * *
* * * *
*
- The user inputs a number n
- The program checks that n is between 1 and 80
- A nested loop prints each row and column
- A star is printed if the position is on the border or the imaginary diagonal (i + j == n - 1)
- Otherwise, spaces are printed to keep the square aligned