Part of the series

Several example codes

~2 min read • Updated Oct 6, 2025

Program Overview

This Python program reads an integer n between 1 and 80 and prints a symmetric diamond pattern using asterisks (*).
The diamond consists of two parts:
- An upper triangle with n rows
- A lower triangle with n - 1 rows
Each row is padded with spaces to center the stars and maintain symmetry.


Python Code:


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

# Validate input
if 1 <= n <= 80:
    # Upper triangle
    for i in range(n):
        row = ' ' * (n - i - 1)
        row += '*'
        if i > 0:
            row += ' ' * (2 * i - 1) + '*'
        print(row)

    # Lower triangle
    for i in range(n - 2, -1, -1):
        row = ' ' * (n - i - 1)
        row += '*'
        if i > 0:
            row += ' ' * (2 * i - 1) + '*'
        print(row)
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 upper triangle prints stars with increasing spacing between them
- The lower triangle mirrors the upper triangle in reverse
- Each row is padded with spaces to align the stars and form a centered diamond


Written & researched by Dr. Shahin Siami