Skip to content
  • SiteMap
  • Our Services
  • Frequently Asked Questions (FAQ)
  • Support
  • About Us

UpdateGadh

Update Your Skills.

  • Home
  • Projects
    •  Blockchain projects
    • Python Project
    • Data Science
    •  Ai projects
    • Machine Learning
    • PHP Project
    • React Projects
    • Java Project
    • SpringBoot
    • JSP Projects
    • Java Script Projects
    • Code Snippet
    • Free Projects
  • Tutorials
    • Ai
    • Machine Learning
    • Advance Python
    • Advance SQL
    • DBMS Tutorial
    • Data Analyst
    • Deep Learning Tutorial
    • Data Science
    • Nodejs Tutorial
  • Blog
  • Contact us
  • Toggle search form
How to Print Patterns in Python

How to Print Patterns in Python

Posted on February 4, 2025February 4, 2025 By Rishabh saini No Comments on How to Print Patterns in Python

How to Print Patterns in Python

Printing patterns is a common exercise in Python programming, especially in coding interviews. The key to printing patterns is using nested loops, where the outer loop controls the number of rows and the inner loop determines the content of each row.

Complete Python Course with Advance topics:-Click here

Basic Concepts of Printing Patterns

  1. Outer loop: Controls the number of rows.
  2. Inner loop: Handles the number of columns or elements in each row.
  3. Whitespace management: Adds spaces to align patterns correctly.

In this tutorial, we will go through various pattern examples, including pyramid, star, and diamond shapes.

1. Simple Pyramid Pattern

n = int(input("Enter the number of rows: "))
for i in range(0, n):
    for j in range(0, i + 1):
        print("*", end=" ")
    print()

Output:

Enter the number of rows: 5
*
* *
* * *
* * * *
* * * * *

2. Reverse Right-Angle Pyramid

rows = int(input("Enter the number of rows: "))
k = 2 * rows - 2
for i in range(0, rows):
    for j in range(0, k):
        print(end=" ")
    k = k - 2
    for j in range(0, i + 1):
        print("* ", end="")
    print()

Output:

Enter the number of rows: 5
        *
      * *
    * * *
  * * * *
* * * * *

3. Downward Half-Pyramid

rows = int(input("Enter the number of rows: "))
for i in range(rows + 1, 0, -1):
    for j in range(0, i - 1):
        print("*", end=' ')
    print()

Output:

Enter the number of rows: 5
* * * * *
* * * *
* * *
* *
*

4. Triangle Pyramid

n = int(input("Enter the number of rows: "))
m = (2 * n) - 2
for i in range(0, n):
    for j in range(0, m):
        print(end=" ")
    m = m - 1
    for j in range(0, i + 1):
        print("* ", end=' ')
    print()

Output:

Enter the number of rows: 5
    *
   * *
  * * *
 * * * *
* * * * *

5. Downward Triangle Pattern

rows = int(input("Enter the number of rows: "))
k = 2 * rows - 2
for i in range(rows, -1, -1):
    for j in range(k, 0, -1):
        print(end=" ")
    k = k + 1
    for j in range(0, i + 1):
        print("*", end=" ")
    print()

Output:

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

6. Diamond Pattern

rows = int(input("Enter the number of rows: "))
k = 2 * rows - 2
for i in range(0, rows):
    for j in range(0, k):
        print(end=" ")
    k = k - 1
    for j in range(0, i + 1):
        print("* ", end="")
    print()
k = rows - 2
for i in range(rows, -1, -1):
    for j in range(k, 0, -1):
        print(end=" ")
    k = k + 1
    for j in range(0, i + 1):
        print("* ", end="")
    print()

Output:

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

7. Double Pyramid Pattern

rows = int(input("Enter the number of rows: "))
for i in range(0, rows):
    for j in range(0, i + 1):
        print("*", end=' ')
    print()
for i in range(rows + 1, 0, -1):
    for j in range(0, i - 1):
        print("*", end=' ')
    print()

Output:

Enter the number of rows: 5
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*

Download New Real Time Projects :-Click here
Complete Advance AI topics:- CLICK HERE

Conclusion

Mastering pattern printing in Python strengthens your understanding of nested loops and helps in improving logical thinking. These patterns are frequently asked in interviews, so practice them well!


print star pattern in python using for loop
how to print patterns in python
how to print patterns in python number
how to print patterns in python different
how to print a pattern in python
number pattern in python
how to print patterns in python pyramid pattern in python using for loop
square pattern in python
star pattern in python using while loop
how to print patterns in python pattern programs pdf
reverse pyramid pattern in python
number pattern program in python using for loop

Post Views: 523
Python Interview Question Tags:how to print patterns in python, pattern in python, pattern printing programs in python, pattern program, pattern program in python, pattern programming in python, patterns in python, programming in python, Python, python design patterns, python pattern, python pattern printing, python pattern programs, python pattern tutorial, python patterns, python programming, python pyramid pattern, Python Tutorial, star pattern in python

Post navigation

Previous Post: Smart Chess AI with Python
Next Post: SQL WITH Clause

More Related Articles

Bubble Sort in Python Bubble Sort in Python Python Interview Question
How to Install Python on Windows: A Step-by-Step Guide - How to Install Python on Windows How to Install Python on Windows: A Step-by-Step Guide Python Interview Question
How to Convert Text to Speech in Python How to Convert Text to Speech in Python Python Interview Question

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

You may also like

  1. How to Install Python on Windows: A Step-by-Step Guide
  2. How to Run Python Program: A Comprehensive Guide for Python Programmers
  3. How to Append Elements to a List in Python
  4. How to Declare a Global Variable in Python
  5. How to Clear the Python Shell
  6. Insertion Sort in Python

Most Viewed Posts

  1. Top Large Language Models in 2025
  2. Online Shopping System using PHP, MySQL with Free Source Code
  3. login form in php and mysql , Step-by-Step with Free Source Code
  4. Flipkart Clone using PHP And MYSQL Free Source Code
  5. News Portal Project in PHP and MySql Free Source Code
  6. User Login & Registration System Using PHP and MySQL Free Code
  7. Top 10 Final Year Project Ideas in Python
  8. Online Bike Rental Management System Using PHP and MySQL
  9. E learning Website in php with Free source code
  10. E-Commerce Website Project in Java Servlets (JSP)
  • AI
  • ASP.NET
  • Blockchain
  • ChatCPT
  • code Snippets
  • Collage Projects
  • Data Science Project
  • Data Science Tutorial
  • DBMS Tutorial
  • Deep Learning Tutorial
  • Final Year Projects
  • Free Projects
  • How to
  • html
  • Interview Question
  • Java Notes
  • Java Project
  • Java Script Notes
  • JAVASCRIPT
  • Javascript Project
  • JSP JAVA(J2EE)
  • Machine Learning Project
  • Machine Learning Tutorial
  • MySQL Tutorial
  • Node.js Tutorial
  • PHP Project
  • Portfolio
  • Python
  • Python Interview Question
  • Python Projects
  • PythonFreeProject
  • React Free Project
  • React Projects
  • Spring boot
  • SQL Tutorial
  • TOP 10
  • Uncategorized
  • Online Examination System in PHP with Source Code
  • AI Chatbot for College and Hospital
  • Job Portal Web Application in PHP MySQL
  • Online Tutorial Portal Site in PHP MySQL — Full Project with Source Code
  • Online Job Portal System in JSP Servlet MySQL

Most Viewed Posts

  • Top Large Language Models in 2025 (8,612)
  • Online Shopping System using PHP, MySQL with Free Source Code (5,210)
  • login form in php and mysql , Step-by-Step with Free Source Code (4,862)

Copyright © 2026 UpdateGadh.

Powered by PressBook Green WordPress theme