PYnative

Python Programming

  • Learn Python
    • Python Tutorials
    • Python Basics
    • Python Interview Q&As
  • Exercises
    • Python Exercises
    • C Programming Exercises
    • C++ Exercises
  • Quizzes
  • Code Editor
    • Online Python Code Editor
    • Online C Compiler
    • Online C++ Compiler
Home » Python » Python Programs to Print Patterns – Print Number, Pyramid, Star, Triangle, Diamond, and Alphabets Patterns

Python Programs to Print Patterns – Print Number, Pyramid, Star, Triangle, Diamond, and Alphabets Patterns

Updated on: September 3, 2024 | 457 Comments

This Python lesson includes over 35+ coding programs for printing Numbers, Pyramids, Stars, triangles, Diamonds, and alphabet patterns, ensuring you gain hands-on experience and confidence in your Python skills.

Printing numbers, stars (asterisk), or other characters in different shapes (patterns) is a frequently asked interview question for freshers. Creating these number and pyramid patterns allows you to test your logical ability and coding skills.

In this lesson, you’ll learn how to print patterns using the for loop, while loop, and the range() function.

This article teaches you how to print the following patterns in Python.

  • Number pattern
  • Pyramid pattern
  • Inverted pyramid pattern
  • Half pyramid pattern
  • Triangle pattern
  • Star (*) or asterisk pattern
  • Diamond Shaped pattern
  • Characters or alphabet pattern
  • Square pattern
Print Pattern in Python
Print Pattern in Python

Table of contents

  • Steps to Print Pattern in Python
  • Number Patterns Programs In Python
    • Pyramid pattern of numbers
    • Inverted pyramid pattern of numbers
    • Inverted Pyramid pattern with the same digit
    • Another inverted half-pyramid pattern with a number
    • Alternate numbers pattern using a while loop
    • Reverse number pattern
    • Reverse Pyramid of Numbers
    • Another reverse number pattern
    • Print reverse number from 10 to 1
    • Number triangle pattern
    • Pascal’s triangle pattern using numbers
    • Square pattern with numbers
    • Multiplication table pattern
  • Pyramid pattern of stars in python
    • Right triangle pyramid of Stars
    • Downward half-Pyramid Pattern of Star
    • Downward full Pyramid Pattern of star
    • Right down mirror star Pattern
    • Equilateral triangle pattern of star
    • Print two pyramids of stars
    • Right start pattern of star
    • Left triangle pascal’s pattern
    • Sandglass pattern of star
    • Pant style pattern of stars
  • Diamond-shaped pattern of stars
    • Another diamond pattern of star
  • Alphabets and letters pattern
    • Pattern to display letter of the word
    • Equilateral triangle pattern of characters/alphabets
    • Pattern of same character
  • More miscellaneous Patterns
    • Pyramid of horizontal number tables
    • Double the number pattern
    • Random number pattern
    • Pyramid of numbers less than 10
    • Pyramid of numbers up to 10
    • Even number pattern
    • Unique pyramid pattern of digits
    • Pattern double number on each column
    • Number reduction pattern
    • Pant style pattern of numbers
    • Pattern with a combination of numbers and stars
  • Practice Problem
  • Next Steps

Steps to Print Pattern in Python

To print any pattern, you must first understand its logic and technique. Use the below steps to print any pattern in Python.

  1. Decide the number of rows and columns

    The number of rows and columns is crucial when printing a pattern. To achieve this, we utilize two loops: outer loops and nested loops. The outer loop is the number of rows, while the inner loop tells us the column needed to print the pattern.

    The input () function accepts the number of rows from a user to decide the size of a pattern.

  2. Iterate rows

    Next, write an outer loop to Iterate the number of rows using a for loop and range() function.

  3. Iterate columns

    Next, write the inner or nested loop to handle the number of columns. The internal loop iteration depends on the values of the outer loop.

  4. Print star or number

    Use the print() function in each iteration of nested for loop to display the symbol or number of a pattern (like a star (asterisk *) or number).

  5. Add a new line after each iteration of the outer loop

    Add a new line using the print() function after each iteration of the outer loop so that the pattern displays appropriately

Algorithm for printing patterns in Python
Algorithm for printing patterns in Python

Also, Solve:

  • Python loop exercise
  • Python Basic Exercise for Beginners

Number Patterns Programs In Python

I have created various programs that print different styles of number patterns. Let’s see them one by one. Let’s print the following number pattern using a for loop.

1  
2 2  
3 3 3  
4 4 4 4  
5 5 5 5 5

Program:

rows = 6
# if you want user to enter a number, uncomment the below line
# rows = int(input('Enter the number of rows'))
# outer loop
for i in range(rows):
    # nested loop
    for j in range(i):
        # display number
        print(i, end=' ')
    # new line after each row
    print('')Code language: Python (python)

In this number pattern, we display a single digit on the first row, two digits on the second row, and three digits on the third row. This process will repeat until the number of rows is reached.

Note:

  • The count of numbers on each row is equal to the current row number.
  • Also, each number is separated by space.
  • We used a nested loop to print the pattern

Pyramid pattern of numbers

Let’s see how to print the following half-pyramid pattern of numbers

1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

Note: In each row, every next number is incremented by 1.

Program:

rows = 5
for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(j, end=' ')
    print('')Code language: Python (python)

Inverted pyramid pattern of numbers

An inverted pyramid is a downward pattern where numbers get reduced in each iteration, and on the last row, it shows only one number. Use reverse for loop to print this pattern.

Pattern

1 1 1 1 1 
2 2 2 2 
3 3 3 
4 4 
5

Program

rows = 5
b = 0
# reverse for loop from 5 to 0
for i in range(rows, 0, -1):
    b += 1
    for j in range(1, i + 1):
        print(b, end=' ')
    print('\r')Code language: Python (python)

Inverted Pyramid pattern with the same digit

Pattern: –

5 5 5 5 5 
5 5 5 5 
5 5 5 
5 5 
5

Program: –

rows = 5
num = rows
# reverse for loop
for i in range(rows, 0, -1):
    for j in range(0, i):
        print(num, end=' ')
    print("\r")
Code language: Python (python)

Another inverted half-pyramid pattern with a number

Pattern: –

0 1 2 3 4 5 
0 1 2 3 4 
0 1 2 3 
0 1 2 
0 1

Program

rows = 5
for i in range(rows, 0, -1):
    for j in range(0, i + 1):
        print(j, end=' ')
    print("\r")
Code language: Python (python)

Alternate numbers pattern using a while loop

Let’s see how to use the while loop to print the number pattern.

Pattern: –

1 
3 3 
5 5 5 
7 7 7 7 
9 9 9 9 9

Program: –

rows = 5
i = 1
while i <= rows:
    j = 1
    while j <= i:
        print((i * 2 - 1), end=" ")
        j = j + 1
    i = i + 1
    print('')
Code language: Python (python)

Reverse number pattern

Let’s see how to display the pattern of descending order of numbers

Pattern 1: –

5 5 5 5 5 
4 4 4 4 
3 3 3 
2 2 
1

This pattern is also called as a inverted pyramid of descending numbers.

Program: –

rows = 5
# reverse loop
for i in range(rows, 0, -1):
    num = i
    for j in range(0, i):
        print(num, end=' ')
    print("\r")
Code language: Python (python)

Reverse Pyramid of Numbers

Pattern 2: –

1 
2 1 
3 2 1 
4 3 2 1 
5 4 3 2 1

Note: It is a downward increment pattern where numbers get increased in each iteration. At each row, the amount of number is equal to the current row number.

Program

rows = 6
for i in range(1, rows):
    for j in range(i, 0, -1):
        print(j, end=' ')
    print("")
Code language: Python (python)

Another reverse number pattern

Pattern: –

5 4 3 2 1 
4 3 2 1 
3 2 1 
2 1 
1

Program: –

rows = 5
for i in range(0, rows + 1):
    for j in range(rows - i, 0, -1):
        print(j, end=' ')
    print()Code language: Python (python)

Print reverse number from 10 to 1

Pattern: –

1
3 2
6 5 4
10 9 8 7

Program: –

start = 1
stop = 2
current_num = stop
for row in range(2, 6):
    for col in range(start, stop):
        current_num -= 1
        print(current_num, end=' ')
    print("")
    start = stop
    stop += row
    current_num = stopCode language: Python (python)

Number triangle pattern

Let’s see how to print the right-angled triangle pattern of numbers

Pattern: –

          1 
        1 2 
      1 2 3 
    1 2 3 4 
  1 2 3 4 5 

Program: –

rows = 6
for i in range(1, rows):
    num = 1
    for j in range(rows, 0, -1):
        if j > i:
            print(" ", end=' ')
        else:
            print(num, end=' ')
            num += 1
    print("")
Code language: Python (python)

Pascal’s triangle pattern using numbers

To build the pascal triangle, start with “1” at the top, then continue placing numbers below it in a triangular pattern.

Each number is the numbers directly above it added together.

Pattern:

1 
1 1 
1 2 1 
1 3 3 1 
1 4 6 4 1 
1 5 10 10 5 1 
1 6 15 20 15 6 1

Program: –

def print_pascal_triangle(size):
    for i in range(0, size):
        for j in range(0, i + 1):
            print(decide_number(i, j), end=" ")
        print()


def decide_number(n, k):
    num = 1
    if k > n - k:
        k = n - k
    for i in range(0, k):
        num = num * (n - i)
        num = num // (i + 1)
    return num

# set rows
rows = 7
print_pascal_triangle(rows)
Code language: Python (python)

Square pattern with numbers

Pattern: –

1 2 3 4 5 
2 2 3 4 5 
3 3 3 4 5 
4 4 4 4 5 
5 5 5 5 5

Program: –

rows = 5
for i in range(1, rows + 1):
    for j in range(1, rows + 1):
        if j <= i:
            print(i, end=' ')
        else:
            print(j, end=' ')
    print()
Code language: Python (python)

Multiplication table pattern

Pattern: –

1  
2  4  
3  6  9  
4  8  12  16  
5  10  15  20  25  
6  12  18  24  30  36  
7  14  21  28  35  42  49  
8  16  24  32  40  48  56  64  

Program: –

rows = 8
# rows = int(input("Enter the number of rows "))
for i in range(1, rows + 1):
    for j in range(1, i + 1):
        # multiplication current column and row
        square = i * j
        print(i * j, end='  ')
    print()
Code language: Python (python)

Pyramid pattern of stars in python

This section will see how to print pyramid and Star (asterisk) patterns in Python. Here we will print the following pyramid pattern with Star (asterisk).

  • Half pyramid pattern with stars(*)
  • Full pyramid pattern with stars
  • Inverted pyramid Pattern with stars
  • Triangle pattern with stars
  • Right-angled triangle pattern with stars

Simple half pyramid pattern: –

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

This pattern is also known as a right angle triangle pyramid.

Program: –

# number of rows
rows = 5
for i in range(0, rows):
    # nested loop for each column
    for j in range(0, i + 1):
        # print star
        print("*", end=' ')
    # new line after each row
    print("\r")
Code language: Python (python)

Right triangle pyramid of Stars

Pattern: –

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

This pattern is also called as mirrored right triangle

Program: –

# number of rows
rows = 5
k = 2 * rows - 2
for i in range(0, rows):
    # process each column
    for j in range(0, k):
        # print space in pyramid
        print(end=" ")
    k = k - 2
    for j in range(0, i + 1):
        # display star
        print("* ", end="")
    print("")
Code language: Python (python)

Alternative Solution:

rows = 5
for j in range(1, rows+1):
    print("* " * j)Code language: Python (python)

Downward half-Pyramid Pattern of Star

Pattern: –

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

Note: We need to use the reverse nested loop to print the downward pyramid pattern of stars

Program: –

rows = 5
for i in range(rows + 1, 0, -1):
    # nested reverse loop
    for j in range(0, i - 1):
        # display star
        print("*", end=' ')
    print(" ")
Code language: Python (python)

Downward full Pyramid Pattern of star

Let’s see how to print reversed pyramid pattern in Python.

Pattern: –

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

Program:

rows = 5
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("")
Code language: Python (python)

Right down mirror star Pattern

Pattern: –

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

In this pattern, we need to use two nested while loops.

Program: –

rows = 5
i = rows
while i >= 1:
    j = rows
    while j > i:
        # display space
        print(' ', end=' ')
        j -= 1
    k = 1
    while k <= i:
        print('*', end=' ')
        k += 1
    print()
    i -= 1
Code language: Python (python)

Equilateral triangle pattern of star

Pattern: –

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

Program: –

print("Print equilateral triangle Pyramid using asterisk symbol ")
# printing full Triangle pyramid using stars
size = 7
m = (2 * size) - 2
for i in range(0, size):
    for j in range(0, m):
        print(end=" ")
    # decrementing m after each loop
    m = m - 1
    for j in range(0, i + 1):
        print("* ", end=' ')
    print(" ")
Code language: Python (python)

Print two pyramids of stars

Pattern: –

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

Program: –

rows = 6
for i in range(0, rows):
    for j in range(0, i + 1):
        print("*", end=' ')
    print(" ")

print(" ")

for i in range(rows + 1, 0, -1):
    for j in range(0, i - 1):
        print("*", end=' ')
    print(" ")
Code language: Python (python)

Right start pattern of star

Pattern: –

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

We also call this pattern as a right pascal’s triangle.

Program: –

rows = 5
for i in range(0, rows):
    for j in range(0, i + 1):
        print("*", end=' ')
    print("\r")

for i in range(rows, 0, -1):
    for j in range(0, i - 1):
        print("*", end=' ')
    print("\r")
Code language: Python (python)

Left triangle pascal’s pattern

Pattern: –

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

Program: –

rows = 5
i = 1
while i <= rows:
    j = i
    while j < rows:
        # display space
        print(' ', end=' ')
        j += 1
    k = 1
    while k <= i:
        print('*', end=' ')
        k += 1
    print()
    i += 1

i = rows
while i >= 1:
    j = i
    while j <= rows:
        print(' ', end=' ')
        j += 1
    k = 1
    while k < i:
        print('*', end=' ')
        k += 1
    print('')
    i -= 1
Code language: Python (python)

Sandglass pattern of star

Pattern: –

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

To print this pattern we need to use two set of three while loops.

Program: –

rows = 5
i = 0
while i <= rows - 1:
    j = 0
    while j < i:
        # display space
        print('', end=' ')
        j += 1
    k = i
    while k <= rows - 1:
        print('*', end=' ')
        k += 1
    print()
    i += 1

i = rows - 1
while i >= 0:
    j = 0
    while j < i:
        print('', end=' ')
        j += 1
    k = i
    while k <= rows - 1:
        print('*', end=' ')
        k += 1
    print('')
    i -= 1
Code language: Python (python)

Pant style pattern of stars

Pattern: –

****************
*******__*******
******____******
*****______*****
****________****
***__________***
**____________**
*______________*

Program: –

rows = 14
print("*" * rows, end="\n")
i = (rows // 2) - 1
j = 2
while i != 0:
    while j <= (rows - 2):
        print("*" * i, end="")
        print("_" * j, end="")
        print("*" * i, end="\n")
        i = i - 1
        j = j + 2Code language: Python (python)

Diamond-shaped pattern of stars

Pattern: –

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

Program: –

rows = 5
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("")Code language: Python (python)

Another diamond pattern of star

Pattern: –

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

Program: –

rows = 5
i = 1
while i <= rows:
    j = rows
    while j > i:
        # display space
        print(' ', end=' ')
        j -= 1
    print('*', end=' ')
    k = 1
    while k < 2 * (i - 1):
        print(' ', end=' ')
        k += 1
    if i == 1:
        print()
    else:
        print('*')
    i += 1

i = rows - 1
while i >= 1:
    j = rows
    while j > i:
        print(' ', end=' ')
        j -= 1
    print('*', end=' ')
    k = 1
    while k <= 2 * (i - 1):
        print(' ', end=' ')
        k += 1
    if i == 1:
        print()
    else:
        print('*')
    i -= 1
Code language: Python (python)

Alphabets and letters pattern

In Python, there are ASCII values for each letter. To print the patterns of letters and alphabets, we need to convert them to their ASCII values.

  • Decide the number of rows
  • Start with ASCII number 65 ( ‘A’)
  • Iterate a loop and in nested for loop use the char function to convert ASCII number to its equivalent letter.

Let’ see now how to print alphabets and letters patterns in Python.

Pattern: –

A  
B C  
D E F  
G H I J  
K L M N O  
P Q R S T U  
V W X Y Z [ \ 

This pattern is knows as right-angled pattern with characters.

Program: –

# ASCII number of 'A'
ascii_number = 65
rows = 7
for i in range(0, rows):
    for j in range(0, i + 1):
        character = chr(ascii_number)
        print(character, end=' ')
        ascii_number += 1
    print(" ")Code language: Python (python)

Pattern to display letter of the word

Let’s see how to print word ‘Python’ in Pattern: –

P
Py
Pyt
Pyth
Pytho
Python

Program: –

word = "Python"
x = ""
for i in word:
    x += i
    print(x)
Code language: Python (python)

Equilateral triangle pattern of characters/alphabets

Pattern: –

            A  
           B C  
          D E F  
         G H I J  
        K L M N O  
       P Q R S T U  
      V W X Y Z [ \  

Program: –

print("Print equilateral triangle Pyramid with characters ")
size = 7
asciiNumber = 65
m = (2 * size) - 2
for i in range(0, size):
    for j in range(0, m):
        print(end=" ")
    m = m - 1
    for j in range(0, i + 1):
        character = chr(asciiNumber)
        print(character, end=' ')
        asciiNumber += 1
    print(" ")Code language: Python (python)

Pattern of same character

Pattern: –

V 
V V 
V V V 
V V V V 
V V V V V 

Program: –

# Same character pattern
character = 'V'
# convert char to ASCII
char_ascii_no = ord(character)
for i in range(0, 5):
    for j in range(0, i + 1):
        # Convert the ASCII value to the character
        user_char = chr(char_ascii_no)
        print(user_char, end=' ')
    print()Code language: Python (python)

Let’s see some more miscellaneous patterns

More miscellaneous Patterns

Pyramid of horizontal number tables

Pattern: –

1 
2 4 
3 6 9 
4 8 12 16 
5 10 15 20 25 
6 12 18 24 30 36 
7 14 21 28 35 42 49 
8 16 24 32 40 48 56 64 
9 18 27 36 45 54 63 72 81 
10 20 30 40 50 60 70 80 90 100 

Program: –

# Pyramid of horizontal tables of numbers
rows = 10
for i in range(1, rows + 1):
    for j in range(1, i + 1):
        print(i * j, end=' ')
    print()
Code language: Python (python)

Double the number pattern

Pattern: –

   1 
   2    1 
   4    2    1 
   8    4    2    1 
  16    8    4    2    1 
  32   16    8    4    2    1 
  64   32   16    8    4    2    1 
 128   64   32   16    8    4    2    1 

Note: In each column, every number is double it’s the preceding number.

Program: –

rows = 9
for i in range(1, rows):
    for j in range(-1 + i, -1, -1):
        print(format(2 ** j, "4d"), end=' ')
    print("")Code language: Python (python)

Random number pattern

   1 
   1    2    1 
   1    2    4    2    1 
   1    2    4    8    4    2    1 
   1    2    4    8   16    8    4    2    1 
   1    2    4    8   16   32   16    8    4    2    1 
   1    2    4    8   16   32   64   32   16    8    4    2    1 
   1    2    4    8   16   32   64  128   64   32   16    8    4    2    1 

Program: –

rows = 9
for i in range(1, rows):
    for i in range(0, i, 1):
        print(format(2 ** i, "4d"), end=' ')
    for i in range(-1 + i, -1, -1):
        print(format(2 ** i, "4d"), end=' ')
    print("")Code language: Python (python)

Pyramid of numbers less than 10

Pattern: –

1 
2 3 4 
5 6 7 8 9

Program: –

current_num = 1
stop = 2
rows = 3

for i in range(rows):
    for column in range(1, stop):
        print(current_num, end=' ')
        current_num += 1
    print("")
    stop += 2
Code language: Python (python)

Pyramid of numbers up to 10

Pattern: –

1 
2 3 
4 5 6 
7 8 9 10

Program: –

current_num = 1
rows = 4
stop = 2
for i in range(rows):
    for column in range(1, stop):
        print(current_num, end=' ')
        current_num += 1
    print("")
    stop += 1Code language: Python (python)

Even number pattern

Pattern: –

10 
10 8 
10 8 6 
10 8 6 4 
10 8 6 4 2

Programs: –

rows = 5
last_num = 2 * rows
even_num = last_num
for i in range(1, rows + 1):
    even_num = last_num
    for j in range(i):
        print(even_num, end=' ')
        even_num -= 2
    print("\r")
Code language: Python (python)

Unique pyramid pattern of digits

Pattern: –

1 
1 2 1 
1 2 3 2 1 
1 2 3 4 3 2 1 
1 2 3 4 5 4 3 2 1

Program: –

rows = 6
for i in range(1, rows + 1):
    for j in range(1, i - 1):
        print(j, end=" ")
    for j in range(i - 1, 0, -1):
        print(j, end=" ")
    print()
Code language: Python (python)

Pattern double number on each column

Pattern: –

0  
0  1  
0  2  4  
0  3  6   9  
0  4  8   12  16  
0  5  10  15  20  25  
0  6  12  18  24  30  36

Program: –

rows = 7
for i in range(0, rows):
    for j in range(0, i + 1):
        print(i * j, end='  ')
    print()Code language: Python (python)

Number reduction pattern

Pattern: –

1 2 3 4 5 
2 3 4 5 
3 4 5 
4 5 
5

Program: –

rows = 5
for i in range(0, rows + 1, 1):
    for j in range(i + 1, rows + 1, 1):
        print(j, end=' ')
    print()Code language: Python (python)

Pant style pattern of numbers

Pattern: –

5 4 3 2 1 1 2 3 4 5 

5 4 3 2     2 3 4 5 

5 4 3         3 4 5 

5 4             4 5 

5                 5

Program: –

rows = 6
for i in range(0, rows):
    for j in range(rows - 1, i, -1):
        print(j, '', end='')
    for l in range(i):
        print('    ', end='')
    for k in range(i + 1, rows):
        print(k, '', end='')
    print('\n')Code language: Python (python)

Pattern with a combination of numbers and stars

Pattern: –

1 * 2 * 3 * 4 

1 * 2 * 3 

1 * 2 

1

Program: –

row = 4
for i in range(0, row):
    c = 1
    print(c, end=' ')
    for j in range(row - i - 1, 0, -1):
        print('*', end=' ')
        c = c + 1
        print(c, end=' ')
    print('\n')
Code language: Python (python)

Also, see how to calculate the sum and average in Python.

Practice Problem

Pattern: –

0 
2 4 
4 8 8 
8 16 16 16

Solution: –

num = 4
counter = 0
for x in range(0, num):
    for y in range(0, x + 1):
        print(counter, end=" ")
        counter = 2 ** (x + 1)
    print()Code language: Python (python)

Next Steps

Solve:

  • Python Basic Exercise for Beginners
  • Python exercise for beginners
  • Python Quiz for beginners

If you don’t find the pattern you are looking for, let me know by leaving a comment and questions below.

Filed Under: Python, Python Basics

Did you find this page helpful? Let others know about it. Sharing helps me continue to create free Python resources.

TweetF  sharein  shareP  Pin

About Vishal

I’m Vishal Hule, the Founder of PYnative.com. As a Python developer, I enjoy assisting students, developers, and learners. Follow me on Twitter.

Related Tutorial Topics:

Python Python Basics

All Coding Exercises:

C Exercises
C++ Exercises
Python Exercises

Python Exercises and Quizzes

Free coding exercises and quizzes cover Python basics, data structure, data analytics, and more.

  • 15+ Topic-specific Exercises and Quizzes
  • Each Exercise contains 25+ questions
  • Each Quiz contains 25 MCQ
Exercises
Quizzes

Comments

  1. Recep says

    November 8, 2025 at 10:26 pm

    “”” places you need to enter “””
    z = “-”
    y = “|” # vertical_character
    x = “_” # horinzontal_character
    roof = 3 # roof_length
    word = “recepdeniz”
    “”” ************************ “””

    word = f”{z}”.join(word)
    sag = y+x
    sol = x+y
    w_index = 0
    print(” ” * ((roof * 2)-1) , f”{x}” * 3)
    for i in range(1, roof+1):
    print(” ” * (2*(roof-i)) ,sol ,sag * (i-1) ,f”|{word[i-1]}|”, sol * (i-1), sag, sep=””)
    w_index += 1
    for j in range(1, (len(word) – (roof-1))):
    print(sag * roof ,f”|{word[w_index]}|”, sol * roof, sep=””)
    w_index += 1
    for l in range(1):
    print(f”{y}”, f”{x}” * ((roof * 5) – (roof-1)), f”{y}”, sep=””)

    # output —>

    ___
    _||r||_
    _||_|-|_||_
    _||_|_|e|_|_||_
    |_|_|_|-|_|_|_|
    |_|_|_|c|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|e|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|p|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|d|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|e|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|n|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|i|_|_|_|
    |_|_|_|-|_|_|_|
    |_|_|_|z|_|_|_|
    |_____________|

    this code output is looking bad on this comment

    Reply
  2. Abhi says

    June 10, 2024 at 12:08 pm

    WAP to print the given pattern:
    1,9,25,49,81
    1,9,25,49
    1,9,25
    1,9
    1

    Reply
    • neelam goswami says

      September 4, 2024 at 12:40 pm

      for loop in range(6,1,-1):
      n=1
      for i in range(loop-1):
      print(n*n,end=” “)
      n+=2
      print(“\n”)

      Reply
    • Favas says

      April 10, 2025 at 11:17 am

      How to print
      123
      654
      789
      121110

      Reply
  3. Abhi says

    June 10, 2024 at 12:05 pm

    Please WAP to print the given pattern:
    1,9,25,49,81
    1,9,25,49
    1,9,25
    1,9
    1

    Reply
    • vanaja says

      February 2, 2025 at 9:10 pm

      n=5
      star=n
      for i in range(1,n+1):
      for j in range(1,star*2,2):
      print(j*j,”,end=”)
      print()
      star-=1

      Reply
  4. Mohan says

    May 28, 2024 at 2:39 pm

    1 2 3
    1 2 3 1 2 3
    1 2 3 1 2 3 1 2 3
    If n=3

    Reply
    • neelam says

      September 4, 2024 at 1:20 pm

      for loop in range(1,4):
      for i in range(loop):
      print(“1 2 3″,end=” “)
      print(“\n”)

      HA HA HA

      Reply
  5. Komal Bansal says

    April 13, 2024 at 9:57 pm

    1 1
    1 2 2 1
    1 2 3 3 2 1
    1 2 3 4 4 3 2 1
    1 2 3 4 5 5 4 3 2 1

    code:-

    n=int(input())
    for i in range(1,n+1):
    for j in range(1,i+1):
    print(j,end=” “)
    for j in range(2*(n-i)):
    print(” “,end=” “)
    for j in range(i,0,-1):
    print(j,end=” “)
    print()

    Reply
    • will smith says

      November 3, 2024 at 9:23 pm

      n = 5
      for i in range(1,n+1):
      for j in range(1,i+1):
      print(j,end=’ ‘)
      for j in range(i,0,-1):
      print(j,end=’ ‘)
      print()

      this is easy I thing what your opinion

      Reply
  6. Arthi.N says

    February 22, 2024 at 5:58 pm

    Please give an algorithm for two pyramid star pattern using nested loop

    Reply
  7. shijin says

    January 10, 2024 at 8:47 am

    E
    D E
    C D E
    B C D E
    A B C D E

    Reply
    • asa says

      January 10, 2024 at 9:51 am

      n=5
      start_char=ord(“A”)
      for i in range(n,0,-1):
      for j in range(n-1):
      print(” “,end=” “)
      for j in range(i,n+1):
      print(chr(start_char+j-1),end=” “)
      print()

      Reply
    • Sid says

      February 17, 2024 at 9:20 pm

      n=int(input(“Enter the number of rows :”)
      for i in range(1,n+1):
      for j in range((n+1-i),(n+1)):
      print(chr(64+j),end=” “)
      print()

      Reply
  8. Himesh c. says

    January 5, 2024 at 11:04 am

    rows = int(input(“enter the number of rows: “))
    for i in range(1, rows + 1):
    for j in range(1, i + 1):
    print(i * j, end=’ ‘)
    print()

    Reply
  9. Amarnath Ganta says

    November 30, 2023 at 11:36 am

    Please write code for this pattern in python:

    #.#.#.#.#.#.#.#.#
    #.#.#.#…#.#.#.#
    #.#.#………..#.#.#
    #.#……………..#.#
    #…………………#
    #.#……………..#.#
    #.#.#……….#.#.#
    #.#.#.#…#.#.#.#
    #.#.#.#.#.#.#.#.#

    Reply
    • Kevin John says

      January 7, 2024 at 1:01 pm

      I did get the output like this . Here is the Code . Hope it Helps

      for i in range(1,5):
      for j in range(5-i):
      if j%2 == 0:
      print(‘#’,end=” “)
      else:
      print(‘.’,end=” “)
      for j in range(2*i-1):
      if i == 1:
      print(‘#’,end=” “)
      else:
      print(‘.’,end=” “)
      for j in range(5-i,0,-1):
      if j%2 == 0:
      print(‘.’,end=” “)
      else:
      print(‘#’,end=” “)
      print()
      for i in range(3,0,-1):
      for j in range(5-i):
      if j%2 == 0:
      print(‘#’,end=” “)
      else:
      print(‘.’,end=” “)
      for j in range(2*i-1):
      if i == 1:
      print(‘#’,end=” “)
      else:
      print(‘.’,end=” “)
      for j in range(5-i,0,-1):
      if j%2 == 0:
      print(‘.’,end=” “)
      else:
      print(‘#’,end=” “)
      print()

      Reply
  10. M says

    September 22, 2023 at 11:10 pm

    Sorry I couldn’t find the box to leave my question there so I replied to this comment
    I wanna print out in this form

    3
    5
    7
    I don’t know where I am doing wrong that my codes don’t work at all
    I’ll appreciate if you answer

    Reply
    • M says

      September 22, 2023 at 11:14 pm

      Actually the form is not like this, I typed in the correct form don’t know why got like this
      It must be like this imagine these numbers as a square
      1 2 3
      4 5 6
      7 8 9
      Imagine all of these numbers printed in the shape of a square and only the numbers (3, 5, 7) must be printed in the form that they are placed in a square

      Reply
      • Kevin John says

        January 7, 2024 at 1:07 pm

        Here is the answer

        count = 1
        for i in range(1,4):
        for j in range(1,4):
        if i + j == 4:
        print(count,end=” “)
        else:
        print(‘ ‘,end=” “)
        count += 1
        print()

        Reply
  11. Manu says

    August 18, 2023 at 2:10 pm

    5 5 5 5 5
    4 5 5 5 5
    3 4 5 5 5
    2 3 4 5 5
    1 2 3 4 5

    I want this as output.

    Reply
    • Vinoth says

      September 15, 2023 at 7:28 pm

      row =5
      num = row

      for i in range(1,row+1):
      for j in range(row):
      print(num,end=” “)
      if(num<row):
      num+=1

      num =row-i
      print("")

      Reply
    • tejesh says

      November 10, 2023 at 11:24 pm

      n=int(input());
      for i in range (0,n):
      for j in range (0,i+1):
      print(n-j,end=’ ‘)
      for j in range (0,n-i-1):
      print(n,end=’ ‘)
      print();

      Reply
    • neelam says

      September 4, 2024 at 3:49 pm

      for loop in range(1,6):
      a=6-loop
      for i in range(loop):
      print(i+a,end=” “)
      for j in range(5,loop,-1):
      print(“5″,end=” “)
      print(“\n”)

      Reply
  12. Nisha says

    July 2, 2023 at 7:50 am

    1
    2 2 2
    3 3 3 3 3
    4 4 4 4 4 4 4
    5 5 5 5 5 5 5 5 5

    Reply
    • chellapillai says

      September 2, 2023 at 12:11 pm

      a=int(input())
      b=1
      for i in range(1,a+a,2):
      for j in range(i):
      print(b,end=” “)
      b+=1
      print()

      Reply
    • Kevin John says

      January 7, 2024 at 1:19 pm

      b = 0
      rows = 10
      for i in range(1,rows,2):
      b += 1
      for j in range(i):
      print(b,end=” “)
      print()

      Reply
    • neelam says

      September 4, 2024 at 4:20 pm

      b=1
      for loop in range(1,6):
      print(f”{loop}”*b, end=’ ‘)
      print(“\n”)
      b+=2

      Reply
  13. swapna says

    May 27, 2023 at 7:38 pm

    s = 3 n= 4 write a program to print a inverted hollow pyramid of n rows using numbers starting from s

    Reply
    • Kevin John says

      January 7, 2024 at 1:27 pm

      count = 3
      for i in range(4,0,-1):
      for j in range(4-i):
      print(‘ ‘,end=” “)
      for j in range(2*i-1):
      if j== 0 or j == 2*i-2:
      print(count+j,end=” “)
      else:
      print(‘ ‘,end=” “)
      print()

      Reply
      • Trupti says

        March 3, 2024 at 4:55 am

        1. 2 2 2 2
        1. 1. 2. 2. 2
        1. 1. 1. 2. 2
        1. 1. 1. 1. 2

        Reply
        • Trupti says

          March 3, 2024 at 4:56 am

          Can someone please solve this

          Reply
  14. dimai says

    May 23, 2023 at 12:05 am

    can someone please solve this

    1
    1 2
    3 2 1
    1 2 3 4
    5 4 3 2 1

    Reply
    • Mohd Saud says

      September 14, 2023 at 12:10 am

      Yes good question
      And the answer is

      n=5
      for i in range(1,n+1):
      if i%2==0:
      for j in range(1,i+1):
      print(j,end=’ ‘)
      print()
      else:
      for j in range(i,0,-1):
      print(j,end=’ ‘)
      print()

      Reply
    • neelam says

      September 5, 2024 at 10:46 am

      for loop in range(1,6):
      if loop%2==0:
      for i in range(1,loop+1):
      print(i,end=” “)
      print(“\n”)
      else:
      for i in range(loop,0,-1):
      print(i,end=” “)
      print(“\n”)

      Reply
    • neelam says

      September 5, 2024 at 10:46 am

      for loop in range(1,6):
      if loop%2==0:
      for i in range(1,loop+1):
      print(i,end=” “)
      print(“\n”)
      else:
      for i in range(loop,0,-1):
      print(i,end=” “)
      print(“\n”)

      Reply
  15. Seenivasan says

    March 27, 2023 at 4:01 pm

    2. input=5
    OUTPUT:
    1
    3 2
    4 5 6
    10 9 8 7

    i need a code for this

    Reply
    • Sivaraman says

      April 14, 2023 at 1:10 pm

      num = int(input("enter the number:"))
      c = 1

      for i in range(num):
      if i % 2 == 0:
      for j in range(i + 1):
      print(c, end=" ")
      c += 1
      else:
      start_num = c + i
      for j in range(i + 1):
      print(start_num, end=" ")
      start_num -= 1
      c += 1
      print()

      Reply
    • BHagyasri says

      April 20, 2023 at 10:16 pm

      n=int(input())
      c=1
      for i in range(1,n+1):
      string=""
      for j in range(1,i+1):
      string=str(c)+" "+string
      c+=1
      print(string)

      Reply
      • Bhagyasri says

        April 20, 2023 at 10:22 pm

        sorry for the above code mistake in j loop. this is actual code and simple way…….

        n=int(input())
        c=1
        for i in range(1,n+1):
        string=””
        for j in range(i+1,1,-1):
        string=str(c)+” “+string
        c+=1
        print(string)

        Reply
  16. ARCHANA TIMMARADDI MADOLLI says

    March 12, 2023 at 8:55 pm

    I need a code for the below pattern..plz help me
    A P Q R
    A B Q R
    A B C R
    A B C D

    Reply
    • Akshaya says

      March 21, 2023 at 5:07 pm

      str1 = "ABCD"
      str2 = "PQR"
      for i in range(4):
      print(str1[0:i+1] + str2[i:]

      Reply
  17. Maneet says

    February 23, 2023 at 11:20 pm

    I have simpler code for

    Your code
    Unique pyramid pattern of digits
    Pattern: –

    1
    1 2 1
    1 2 3 2 1
    1 2 3 4 3 2 1
    1 2 3 4 5 4 3 2 1

    Program: –

    rows = 6
    for i in range(1, rows + 1):
    for j in range(1, i - 1):
    print(j, end=" ")
    for j in range(i - 1, 0, -1):
    print(j, end=" ")
    print()

    my code

    rows = 6
    a = 1
    for i in range(1, rows + 1):
    for j in range(1, i - 1):
    print(j, end=" ")
    print(a**2)
    a = (a*10)+1

    the series you wrote goes like this
    1
    (11)^2
    (111)^3

    .
    I hope my suggestion is valuable
    thanks!!

    Reply
    • Mahi says

      March 3, 2023 at 12:12 am

      S
      AS
      IAS
      AS
      S

      Code plz…yah…

      Reply
      • Nilesh Morekar says

        March 21, 2023 at 10:05 am

        s='IAS'
        for i in range(3):
        for j in range(i+1):
        print(s[j+2-i] , end=' ')
        print()
        for i in range(1):
        for j in range(2-i):
        print(s[j+1] , end=' ')
        print()
        print(s[2])

        Reply
    • neelam says

      September 4, 2024 at 4:40 pm

      for loop in range(1,6):
      for i in range(1,loop):
      print(i,end=” “)
      for j in range(loop):
      print(loop-j,end=” “)
      print(“\n”)

      Reply
  18. Manasa says

    February 18, 2023 at 2:58 pm

    1
    2 2 2
    3 3 3 3 3

    Reply
    • Nilesh Morekar says

      March 21, 2023 at 10:09 am

      for i in range(3):
      for j in range(2*i+1):
      print( str(i+1) , end=' ')
      print()

      Reply
    • Bhagyasri says

      April 20, 2023 at 10:29 pm

      i wrote dynamic format , user want’s to give any nymber…..

      n=int(input())
      c=1
      for i in range(1,n+1):
      for j in range(1,i*2):
      print(str(c)+" ",end="")
      print(" ")
      c+=1

      Reply
  19. osaami says

    January 9, 2023 at 8:41 pm

    1******
    12*****
    123****
    1234***
    12345**
    123456*
    1234567

    Reply
    • neelam says

      September 4, 2024 at 5:29 pm

      n=7
      for loop in range(1,9):
      for i in range(1,loop):
      print(i,end=” “)
      print(“*”*n,end=” “)
      n-=1
      print(“\n”)

      But it is also printing 8 “*” on top of the pyramid. please reply to remove it. else, the pattern is as is.

      Reply
    • neelam says

      September 4, 2024 at 5:30 pm

      n=7
      for loop in range(1,9):
      for i in range(1,loop):
      print(i,end=” “)
      print(“*”*n,end=” “)
      n-=1
      print(“\n”)

      But it is also printing 8 “*” on top of the pyramid. please reply to remove it. else, the pattern is as is.

      Reply
  20. KAMAL SINGH says

    January 3, 2023 at 10:05 pm

    If n = 5
    e
    e
    e
    e
    e@@@@@
    e @@@
    e @
    e
    e

    Reply
  21. Himanshu Rajore says

    December 31, 2022 at 5:15 pm

    Please write code for this program.

    1
    2 7
    3 8 13
    4 9 14 19
    5 10 15 20 25

    Reply
    • Razal says

      January 3, 2024 at 7:15 pm

      row = 5
      for i in range(1,row + 1):
      c = 0
      for j in range(1, i + 1):
      print(i+(5*c), end=’ ‘)
      c += 1
      print()

      Reply
  22. Himanshu Rajore says

    December 31, 2022 at 5:09 pm

    Please write code to print this pattern:-

    1
    2 7
    3 8 13
    4 9 14 19
    5 10 15 20 25

    Reply
    • Vinoth R says

      September 15, 2023 at 7:41 pm

      row =5
      for i in range(1,row+1):
      for j in range(i):
      print(format(i+(j*row),”2d”),end=” “)
      print()

      Reply
      • Prince sardar says

        December 13, 2023 at 10:54 am

        1
        2 3
        4 5 6
        7 8 9 1
        2 3 4 5 6
        7 8 9 1 2 3
        4 5 6 7 8 9 1

        Reply
        • Lubna says

          January 2, 2024 at 8:23 am

          n=7
          counter=1
          for i in range(n):
          for j in range(i+1):
          print(counter,end=” “)
          counter=counter % 9 + 1
          print()

          Reply
    • Nagasai says

      September 20, 2023 at 2:35 am

      n=int(input())
      for i in range(n):
      var=i+1
      for j in range(i+1):
      print(var,end=” “)
      var+=n
      print()

      Reply
  23. Isna says

    November 30, 2022 at 8:46 am

    please teach me how to display a pattern by entering a number first, like number 4…use
    pattern = int(input)

    – – – – – 4
    – – – -3 4 5
    — -2 3 4 5 6
    -1 2 3 4 5 6 7

    Reply
  24. Isna says

    November 30, 2022 at 8:40 am

    please teach me how to display a pattern by entering a number first, like number 4…use pattern = int(input)
    4
    3 4 5
    2 3 4 5 6
    1 2 3 4 5 6 7

    Reply
  25. Hassan Ibrahim says

    November 25, 2022 at 12:00 pm

    Thank you more

    Reply
  26. vishal says

    November 4, 2022 at 7:41 pm

    input=7
    output

    1 1
    2 2
    3 3
    4
    3 3
    2 2
    1 1

    Reply
    • jahangeer alam says

      November 22, 2022 at 11:52 pm

      n=int(input("enter the number"))
      k=int(input("enter the number"))
      a=n+k
      b=a
      for i in range(1,n+1):
      if i<k:
      print(a)
      a=a+b
      elif i==k:
      print(k)
      else:
      a=a-b
      print(a)

      Reply
    • Armaan Indani says

      November 27, 2022 at 8:46 am

      x=int(input("input= "))
      mid=x//2+1
      for i in range(1,mid):
      print(i,i)
      print(mid)
      for i in range(mid-1,0,-1):
      print(i,i)

      Reply
      • neelam says

        September 5, 2024 at 11:08 am

        n=3
        for loop in range(1,8):
        if loop<4:
        for i in range(1,3):
        print(loop,end=" ")
        print("\n")
        elif loop==4:
        print("4",end=" ")
        print("\n")
        else:
        for i in range(1,3):
        print(n,end=" ")
        n-=1
        print("\n")

        Reply
  27. Aditya says

    November 1, 2022 at 11:07 pm

    *
    *1*
    *121*
    *12321*
    *121*
    *1*
    *
    pls answer this one

    Reply
    • nagasai says

      September 22, 2023 at 11:16 am

      n=int(input())
      for i in range(n):
      for j in range(i+1):
      if j==0:print(‘*’,end=””)
      else:print(j,end=””)
      for j in range(i):
      if j==i-1:
      print(“*”,end=””)
      else:
      print(i-j-1,end=””)
      print()
      x=n-1
      for i in range(x):
      for j in range(x-i):
      if j==0:
      print(“*”,end=””)
      else:
      print(j,end=””)
      for j in range(x-i-1):
      if j==x-i-2:
      print(“*”,end=””)
      else:
      print(x-i-2-j,end=””)

      print()

      Reply
  28. ashok kumar says

    November 1, 2022 at 4:15 pm

    can anyone solve this pattern
    24
    23 22
    21 20 19
    18 17 16 15
    14 13 12 11 10

    Reply
    • Armaan Indani says

      November 27, 2022 at 8:39 am

      x=24
      for i in range(5):
      for j in range(i+1):
      print(x,end=" ")
      x-=1
      print()

      Reply
  29. ashok kumar says

    November 1, 2022 at 4:14 pm

    great job sir
    hats of to you..

    Reply
  30. christian says

    October 19, 2022 at 5:04 pm

    an alternative solution to the random number pattern.

    for i in range(1,9):
    k = 2
    for j in range(i*2-1):
    if 2**j=2**i:
    print(2**(i-k),'',end='')
    k = k + 1
    print()

    Reply
  31. christian says

    October 17, 2022 at 4:14 pm

    an alternative solution to: “Print reverse number from 10 to 1”

    k = 0
    for i in range(5):
    for j in range(i):
    print(k+i-j,'',end='')
    k = k+i
    print()

    Reply
  32. luliao says

    September 17, 2022 at 2:49 pm

    How can you get this output:
    enter a number: 50

    1
    23
    456
    78910
    1112131415
    161718192021
    22232425262728
    2930313233343536
    373839404142434445
    4647484950
    Reply
    • Reddy says

      October 17, 2022 at 2:12 pm

      a=50
      c=1
      for i in range(1,a+1):

      b=""
      for j in range(i):
      if c<=50:
      b=b + str(c)
      c=c+1
      print(b)

      Reply
    • Armaan Indani says

      November 27, 2022 at 8:56 am

      x=1
      brk=False
      n=int(input("Enter the number: "))
      for i in range(n):
      for j in range(i):
      if x<=n:
      print(x,end='')
      x+=1
      else:
      brk=True
      break
      if brk==True:
      break
      print()

      Reply
  33. Jackson says

    September 15, 2022 at 9:24 pm

    Can anyone help me make a pyramid where the length of the left side scales based on a entered integer using loops? ex
    Enter an integer between 1 and 5: 5

                1
             2 3
          3 4 5
       4 5 6 7
    5 6 7 8 9
    Reply
    • Akshay says

      September 18, 2022 at 6:41 am

      for i in range(1, n+1):
          for j in range(i):
              print(i+j, end="")
          print('\r')
      Reply
      • Akshay says

        September 18, 2022 at 6:42 am

        for i in range(1, n+1):
            for j in range(i):
                print(i+j, end="")
            print('\r')
        Reply
        • keta vora says

          October 3, 2022 at 6:04 pm

          please solve this

          4 3 2 1
          3 4 3 2
          2 3 4 3 
          1 2 3 4
          Reply
          • Reddy says

            October 17, 2022 at 4:48 pm

            can you please elaborate the question

          • Armaan Indani says

            November 27, 2022 at 9:29 am

            n=int(input("Enter Number: "))
            for i in range(1,n+1):
            for j in range(i,0,-1):
            print(n+1-j,end=" ")
            for j in range(n-i):
            print(n-1-j,end=" ")
            print()

    • Armaan Indani says

      November 27, 2022 at 9:09 am

      x=1
      n=int(input("Enter the number: "))
      for i in range(1,n):
      print(" "*(3*(n-i)),end="")
      for j in range(i):
      print(x,end=" ")
      x+=1
      x=(x-i)+1
      print()

      Reply
    • Armaan Indani says

      November 27, 2022 at 9:13 am

      n=int(input())
      for i in range(1, n+1):
      print(" "*(3*(n-i)),end="")
      for j in range(i):
      print(i+j, end=" ")
      print()

      Reply
    • neelam says

      September 5, 2024 at 11:21 am

      for loop in range(1,6):
      for i in range(5,loop,-1):
      print(” “,end=” “)
      n=loop
      for i in range(1,loop+1):
      print(n,end=” “)
      n+=1
      print(“\n”)

      Reply
  34. hi says

    September 1, 2022 at 3:22 pm

      *
       ***
      *****
     *******
    &&&&&&&&&
     *******
      *****
       ***
        *
    Reply
    • hmmm says

      September 1, 2022 at 3:23 pm

      9 9 9 9 9 9 9 9 9 
         7 7 7 7 7 7 7 
           5 5 5 5 5 
             3 3 3 
               1
      Reply
      • Armaan Indani says

        November 27, 2022 at 9:41 am

        x=int(input("Enter Number of rows: "))
        for i in range(x):
        print(" "*(2*i),end="")
        for j in range(2*(x-i)-1):
        print(2*(x-i)-1,end=" ")
        print()

        Reply
    • Armaan Indani says

      November 27, 2022 at 9:35 am

      n=int(input("Enter Number of rows(odd): "))
      x=n//2
      for i in range(x):
      print(" "*(x-i),end="")
      print("*"*(2*i+1))
      print("&"*(2*x+1))
      for i in range(x-1,-1,-1):
      print(" "*(x-i),end="")
      print("*"*(2*i+1))

      Reply
  35. sohail says

    August 26, 2022 at 11:26 pm

    Or this:

    1 2
    1    3
    1        4
    1            5
    1               6
    Reply
    • Reddy says

      October 17, 2022 at 4:55 pm

      if wrong, please mention
      a=int(input())
      for i in range(2,a+1):
      b="1 "+" "*(2*i-4)+str(i)
      print(b)

      Reply
    • neelam says

      September 5, 2024 at 12:28 pm

      for loop in range(6):
      print(“1″,end=” “)
      for gap in range(0,loop):
      print(” “,end=” “)
      print(loop+1,end=” “)
      print(“\n”)

      Reply
  36. sohail says

    August 26, 2022 at 11:22 pm

    Someone, please print this:

    # #
    #  #
    #.   #
    #      #
    #.       #
    #.         #
    Reply
    • Reddy says

      October 17, 2022 at 4:45 pm

      can you please elaborate the question

      Reply
  37. Nthabiseng Motene says

    July 22, 2022 at 2:19 pm

    5 4 3 2 1 
    4 3 2 1 
    3 2 1 
    2 1 
    1
    Reply
    • Reddy says

      October 17, 2022 at 4:44 pm

      a=int(input())
      for i in range(1,a+1):
      b=""
      for j in range(1,a-i+2):
      b=str(j)+" "+b
      print(b)

      Reply
  38. Shreya says

    July 18, 2022 at 8:20 pm

    Wap to print all the pattern

    #
    #@
    #@#
    #@#@
    Reply
    • Reddy says

      October 17, 2022 at 5:06 pm

      a="#@"
      c=""
      for i in range(int(input())):
      if i%2==0:
      b=a[0]
      else:
      b=a[1]
      c=c+b
      print(c)

      #in place of the index, you can directly assign them separately

      Reply
  39. Shreya says

    July 18, 2022 at 8:19 pm

    How to wap this pattern

    1       1      1
    12      2      3
    123     6      6
    1234    24      10
    Reply
    • Reddy says

      October 17, 2022 at 5:27 pm

      b=int(input())
      n=""
      m=1
      a=0
      for i in range(1,b+1):
      n=n+ str(i)
      m=m*i
      a=a+ i
      print(n+" "*(b)+str(m)+" "*(b)+str(a))

      I cannot maintain the spaces, if any one knows, please mention it.

      Reply
  40. Kokab says

    June 22, 2022 at 8:35 pm

    How to print this pattern

    1
    2 3
    4 5 6 
    7 8 9 10
    .
    .
    .
    .
    Reply
  41. muditha says

    May 26, 2022 at 1:01 pm

    Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying “prime”, and if it is not a prime number saying “not a prime”. Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.

    
    i = int(input())
    j = 5 # fix the code (1) 
    while (j  i/j): 
        print ("prime") 
    Reply
  42. muditha says

    May 26, 2022 at 12:58 pm

    Complete the code to find if a given number is a prime number? The program will take a positive integer greater than 1 as input and indicate if it is a prime number by saying “prime”, and if it is not a prime number saying “not a prime”. Note there are 3 places in the given code that you need to fix for this code to work properly and give the expected output.

    i = int(input())
    j = 5 # fix the code (1) 
    while (j  i/j): 
        print ("prime")
    Reply
  43. muditha says

    May 26, 2022 at 12:55 pm

    how to print this
    input result

    *
    **
    **
    *****
    *****
    *****
    *****
    *****
    val = int(input())
    for x in range (0, val):
    print(‘*’,end=”)
    val = int(input())
    for x in range (0, val):
        print('*',end='')

    please help to fill this code

    Reply
  44. Muskan Agrawal says

    May 4, 2022 at 12:50 pm

    Write a program to print the below number pattern
    for n=6

    1
    3   5
    7   9   11
    1   3   5    7
    9   11  1   3   5 
    7   9    11  1   3   5

    Use a variable ‘n’ in the program to control the number of output rows
    As here for n=6, the number of rows is 6

    Reply
  45. Anonymous says

    April 17, 2022 at 3:08 pm

    Can someone pls help me with this?

    A
    AP
    APP
    APPL
    APPLE

    It’s so hard in Python

    Reply
    • Vab says

      June 30, 2022 at 3:36 pm

      name="Apple"
      y=""
      for x in name:
          y+=x
          print(y)
      Reply
    • Armaan Indani says

      November 27, 2022 at 10:37 am

      s1="APPLE"
      for i in range(1,len(s1)+1):
      print(s1[:i])

      Reply
    • neelam says

      September 5, 2024 at 1:10 pm

      a=”APPLE”
      for loop in range(6):
      for i in range(loop):
      print(a[i],end=” “)
      print(“\n”)

      Reply
  46. A.Neelima says

    March 21, 2022 at 4:45 pm

    . . . . 0 . . . . 
    . . . 0 0 0 . . . 
    . . 0 0 0 0 0 . . 
    . 0 0 0 0 0 0 0 . 
    0 0 0 0 0 0 0 0
    Reply
  47. srikanth says

    March 13, 2022 at 11:22 am

    How to print

     1
     3   2
     4   5   6
    10  9    8  7
    11 12 13 14 15
    Reply
  48. Chetan says

    January 6, 2022 at 11:29 pm

    I want a program of this pattern please help,

    1
    01
    101
    0101
    10101
    Reply
    • Ramya P says

      November 23, 2022 at 3:28 pm

      num=5
      for i in range(5):
      for j in range(0,i+1):
      if j%2==0: print(0, end='')
      else:
      print(1,end='')
      print()

      Reply
    • Armaan Indani says

      November 27, 2022 at 10:35 am

      n=10
      x=1
      for i in range(n):
      for j in range(i+1):
      print(x%2,end="")
      x+=1
      print()

      Reply
  49. Srinivas says

    January 6, 2022 at 2:29 pm

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

    Pls solve this

    Reply
  50. farah says

    December 9, 2021 at 5:09 pm

    please i need answer:
    Write a program to display a shape using star (*) based on the user selection. The program
    will repeatedly ask the user to determine the shape number (any number from 1-6, see
    below) and its parameters (i.e. width, height). The program will stop asking the user for
    more inputs only when the user inputs 7 (which means exit).
    The user will see the following menu:
    1: Square
    2: Rectangle
    3: Left Lower Triangle
    4: Right Lower Triangle
    5: Left Upper Triangle
    6: Right Upper Triangle
    7: Exit
    Enter the number of the shape you want to be drawn on the screen:
    – In case the user selected 1, you will ask the user to enter the length of the square,
    and your program will then call a function that will draw the square based on the
    given length.
    – In case the user selected 2, you will ask the user to enter the width and the height of
    the rectangle and your program will then call a function that will draw the rectangle
    based on the given width and height
    – In case the user selected 3 or 4 or 5 or 6, you will ask the user to enter the length of
    the triangle. In your code, you will write 4 functions to draw the corresponding 4
    triangle types based on the given length.
    For example, given a length=5
    o Left Lower Triangle function will draw:

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

    o Right Lower Triangle will draw:

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

    o Left Upper Triangle will draw:

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

    o Right Upper Triangle will draw:

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

    – In case the user selected 7, your program should stop running
    – In case the user selected a number, not in the range (1-7), your program will print a
    message “invalid selection, try again”, and the menu should be displayed again.
    – After a user select any of the number 1-6, and after drawing the required shape, the
    the menu should be displayed again asking the user for a new selection.

    Reply
  51. MB says

    December 6, 2021 at 12:53 am

    I’m looking to solve the following:

    Write a program that accepts a positive integer, N, that represents the number of rows of a right triangle. Each row of the triangle consists of one or more ‘*’ characters. Use a while loop or a for loop, to print the right triangle of the character ‘*’ where the triangle is one character wide at its narrowest point and N characters wide at its widest point. Then, display a blank line followed by the number of times the ‘*’ character is shown in the triangle.

    Sample Input – 9
    Sample output:

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

    45
    ____________________________________

    What I have so far:

    N = 9
    for i in range(0, N +1):
        for j in range(1, i + 1):
            print("*", end='')
        print('')
    print ('')

    _________________________________

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

    >>>
    __________________________________

    Not sure how to calculate or display the total number of (*’s) listed.

    Also, not sure if needed, but it would be cool to have a message printed stating that “only positive integers are accepted in this code”, if a negative integer is input as a value for ‘N’. Or something like this. Just trying to add some flair to the program.

    Reply
    • Armaan Indani says

      November 27, 2022 at 10:42 am

      n=9
      count=0
      for i in range(n+1):
      for j in range(1,i+1):
      print("*", end='')
      count+=1
      print()
      print("Total stars =",count)

      Just increase the count by 1 each time you print a star

      Reply
  52. joshua says

    November 26, 2021 at 5:46 pm

    ***  ***
     **   **
      *    *
    Reply
  53. Vishwa Thakkar says

    November 25, 2021 at 10:21 pm

    A static program to print 1
    3 2
    6 5 4…..

    Reply
  54. ansh says

    October 20, 2021 at 11:39 am

    *000*000*
    0*00*00*0
    00*0*0*00
    000***000

    I need help with this code

    Reply
  55. pooja says

    October 13, 2021 at 10:35 pm

    Need Help
    Print Pattern

    11
    ***
    2222
    *****
    333333
    Reply
    • Karanbir says

      December 17, 2021 at 3:42 am

      
      count=1
      flag=0
      num=int(input('Enter number:'))
      row=(num)
      col=2
      for i in range(row):
          for j in range(col):
              if flag==0:
                  print(count,end='')
              else:
                  print('*',end='')
                  
          if i%2==0:
              flag=1
              count+=1
          else:
              flag=0
          col+=1
          print('\r')
      Reply
    • Armaan Indani says

      November 27, 2022 at 10:47 am

      n=5
      for i in range(1,n+1):
      for j in range(2*i):
      print(i,end="")
      print()
      print("*"*(2*i+1))

      Reply
  56. bhat says

    September 18, 2021 at 3:05 pm

    123456
    23456
    3456
    456
    56
    6
    56
    456
    3456
    23456
    123456

    can anyone tell code for this pattern

    Reply
    • Athena says

      October 7, 2021 at 8:05 pm

      for i in range(5):
          for j in range(i+1, 7):
              print(j, end="")
          print()
      for i in range(6):
          for j in range(6-i, 7):
              print(j, end="")
          print()
      Reply
    • Armaan Indani says

      November 27, 2022 at 11:00 am

      n=int(input())
      for i in range(n,0,-1):
      for j in range(1,i+1):
      print(n-i+j,end="")
      print()
      for i in range(1,n):
      for j in range(i+1):
      print(n-i+j,end="")
      print()

      Reply
  57. Arya says

    July 30, 2021 at 12:02 am

    Can anyone help me out with this

    ***
    * *
    ***
    Reply
    • Logesh says

      January 29, 2022 at 9:33 am

      Inp=int(input())
      For I in range(1,Inp+1):
             For j in rage(1,Inp+1,1):
                    If i==1 or j==1 or i==Inp or j==Inp:
                        Print("*")
      Reply
    • Deviprasad says

      October 21, 2022 at 5:17 pm

      n=int(input())
      for i in range(1,n+1):
      for j in range(1,n+1):
      if i==1 or j==1 or i==n or j==n:
      print("*",end='')
      else:
      print(' ',end='')
      print()
      v

      Reply
  58. Ananya Shee says

    July 21, 2021 at 5:58 pm

    Please help to solve the pattern

    123
    1123
    2246
    3369

    Thank you

    Reply
  59. Bala bhaskar says

    July 19, 2021 at 1:43 pm

    Hi Vishal, can u please help in solving the following patterns of rows “n”

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

    and

    ______
    |    /
    |   /
    |  /
    | /
    |/
    Reply
    • Athena says

      October 7, 2021 at 8:10 pm

      print("------")
      for i in range(5):
          for j in range(1):
              print("|", end="")
          for j in range(5-i-1, 0, -1):
              print(" ", end="")
          for j in range(1):
              print("/", end="")
          print()
      Reply
    • Armaan Indani says

      November 27, 2022 at 11:07 am

      n=10
      print("_"*(n+1))
      for i in range(n):
      print("|",end="")
      print(" "*(n-i-1),end="")
      print("/")

      Reply
  60. adi says

    June 14, 2021 at 10:05 am

    Pattern double number on each column using while loop

    
    n = int(input()) 
    i = 0 
    while(i<=n):
        j = 1 
        p = 1 
        while(j1):
                print(p*i,end=" ")
                p=p+1 
            else:
                print(0,end=" ")
            j=j+1 
        print()
        i=i+1 
    
    Reply
    • adi says

      June 14, 2021 at 10:10 am

       
      n = int(input()) 
      i = 0 
      while(i<=n):
          j = 1 
          p = 1 
          while(j1):
                      print(p*i,end=" ")
                      p=p+1 
                  else:
                     print(0,end=" ")
                  j=j+1 
          print()
          i=i+1
      Reply
      • adi says

        June 14, 2021 at 10:12 am

        there is some problem with this website sir
        mine (j<=1) and if the statement is not printing
        Please check asap

        Reply
  61. adi says

    June 13, 2021 at 8:30 pm

    Practise Problem
    Pattern using while loop

     
    n = int(input())
    print(0)
    i = 1 
    q = 2 
    while(i<n):
        j = 1 
        p = q 
        while(j1):
                print(p*2,end=" ")
            else:
                print(p,end=" ")
            j=j+1 
        print()
        q=q*2
        i=i+1 
    
    Reply
    • adi says

      June 13, 2021 at 8:36 pm

      the first solution is kind of wrong
      this is the right solution

      
      n = int(input())
      print(0)
      i = 1 
      q = 2 
      while(i<n):
          j = 1 
          p = q 
          while(j1):
                  print(p*2,end=" ")
              else:
                  print(p,end=" ")
              j=j+1 
          print()
          q=q*2
          i=i+1 
      
      Reply
      • adi says

        June 14, 2021 at 10:08 am

        n = int(input())
        print(0)
        i = 1 
        q = 2 
        while(i<n):
            j = 1 
            p = q 
            while(j1):
                    print(p*2,end=" ")
                else:
                    print(p,end=" ")
                j=j+1 
            print()
            q=q*2
            i=i+1
        Reply
      • Muhammad Shamim says

        November 22, 2023 at 10:50 am

        I nee code for the following out put in python
        1
        4 9
        16 25 36
        49 64 81 100

        Reply
  62. adi says

    June 13, 2021 at 8:12 pm

    Even number pattern using while loop

     
    o = int(input())
    n = int(input()) 
    i = 1 
    q = o 
    while(i<=n):
              j = 1 
              p = q
              while(j<=i):
                    print(p,end=" ")
                    p=p-2
                    j=j+1
               print()
               i=i+1
    Reply
  63. adi says

    June 13, 2021 at 7:57 pm

    Double the number pattern using while loop

    
    n = int(input())
    print(1)
    i = 1 
    q = 2 
    while(i<n):
             j = 1 
            p = q 
            while(j<=i+1):
                     if(j==(i+1)):
                             print(1,end="") 
                     else: 
                          print(p,end="")
                          p=p//2 
                      j=j+1
             print()
             q=q*2
             i=i+1
    Reply
  64. adi says

    June 13, 2021 at 7:50 pm

    Pattern with a combination of numbers and stars

    
    n = int(input())
    i = 1 
    p = n 
    while(i<=n):
              j = 1
             o = 1 
             while(j<=((p-1)+p)):
                       if(j==1):
                               print(1,end="")
                       elif(j%2==0):
                               print("*",end="")
                       else:
                           print((j-o),end="")
                           o=o+1
                        j=j+1
             print()
             p=p-1
             i=i+1
    Reply
  65. sneha says

    June 7, 2021 at 10:44 pm

    want this output

    1
    2 2 2
    3 3 3 3 3
    Reply
    • adi says

      June 12, 2021 at 8:10 pm

      Here is the solution to this question

      n = int(input())
      i = 1 
      p = 1 
      while(i<=n):
          j = 1 
          while(j<=p):
              print(i,end=" ")
              j=j+1 
          print()
          p=p+2 
          i=i+1
      Reply
      • adi says

        June 12, 2021 at 8:12 pm

        n = int(input())
        i = 1
        p = 1
        while(i<=n):
                j = 1
        while(j<=p):
                print(i,end=" ")
        j=j+1
        print()
        p=p+2
        i=i+1
        Reply
        • adi says

          June 12, 2021 at 8:14 pm

          n = int(input())
          i = 1
          p = 1
          while(i<=n):
                  j = 1
                 while(j<=p):
                         print(i,end=" ")
                         j=j+1
                 print()
                 p=p+2
                 i=i+1
          Reply
          • kabir says

            June 12, 2021 at 8:21 pm

            
            n = int(input())
            i = 1
            p = 1
            while(i<=n):
                     j = 1
                    while(j<=p):
                            print(i,end=" ")
                            j=j+1
                    print()
                    p=p+2
                    i=i+1
  66. sai vikas says

    May 29, 2021 at 5:51 pm

    Given an integer N, write a program to print a right angle triangle pattern similar to the pattern shown below

        /|
       / |
      /  |
     /   |
    /____|
    

    Input

    The input will be a single line containing a positive integer (N).
    Output

    The output should be N lines containing the triangle pattern.

    Reply
  67. Ameya Kshatriya says

    May 8, 2021 at 4:50 pm

    #Star pattern for beginners 
    #This prints full pyramid
    
    n=int(input())
    s=n-1
    for i in range(1,n+1) :
        for j in range(s+1) :
            print(s*' ',i*'* ')
            s=s-1
            i=i+1
    Reply
  68. Kartela says

    April 17, 2021 at 12:44 pm

    Please help me with this pattern

    * * * * *
    * * *
    * * *
    * * *
    * * * * *
    Reply
    • Ashish says

      May 19, 2021 at 10:00 am

      row = 5
      for i in range(1,row+1):
      	for j in range(1,row+1):
      		if i > 1 and i  (row-2):
      			print(" ", end = "  ")
      		else:
      			print("*", end = "  ")
      	print()
      Reply
    • Shubham says

      May 25, 2021 at 5:08 pm

      for row in range(5):
          for col in range(5):
      
              if ((col == 0 or col == 4 or col == 1) and (row != 0 or row != 4) or (row == 0 or row == 4) and (col > 0 and col < 4)):
      
                  print("*", end="")
          else:
                  print(end=" ")
          print()
      Reply
  69. alaa says

    April 6, 2021 at 3:17 pm

    1
    21
    123
    4321
    12345

    who can draw it for Me !!

    Reply
    • adi says

      June 12, 2021 at 10:11 pm

      Here is the solution for your question

      
          n = int(input())
          i = 1 
          q = 1  
          while(i<=n):
                j = 1 
                p = q 
                o = 1 
                while(j<=i):
                        if(i%2==0):
                               print(p,end=" ")
                               p=p-1
                        else:
                              print(o,end=" ")
                              o=o+1 
                        j=j+1 
                 print()
                 q=q+1 
                 i=i+1
      Reply
      • Hinata Uzamaki says

        June 19, 2021 at 4:33 pm

         
        n =int(input()) 
        for i in range(1,n+1):
            if(i%2==0):
                for j in range(1,i+1):
                    print(i,end="")
                    i=i-1
            else:
                for j in range(1,i+1):
                    print(j,end="")
            print()
        
        Reply
  70. Qirat says

    March 27, 2021 at 1:22 am

    Plz anyone tell me how this pattern form

    *****
      ****
        ***
          **
            *
          **
        ***
      ****
    *****
    Reply
    • Avijit says

      September 7, 2021 at 9:14 pm

      rows = 5
      for i in range(1, rows + 1):
          for s in range(1, i+1):
              print("   ", end = ' ')
          for j in range(rows+1, i , -1):
              print('*', end='')
          print()
      rows1=rows-1
      for i in range(1, rows1 + 1):
          for s in range(rows1+1,i,-1):
              print("   ",end=' ')
          for j in range(0, i+1):
              print('*', end='')
          print()
      Reply
  71. SAHIL says

    March 20, 2021 at 12:09 pm

    k = k + 1
        for j in range(0, i + 1):
            print("*", end=" ")
        print("")

    Output:

    *****
    ****
    ***
    **
    *
    Reply
  72. Alsya says

    March 2, 2021 at 8:47 am

    Can you please help me with this kind of pattern, thank you.

    Enter the number of line: 10

    11 12 13 14 15 16 17 18 19 20
    21 22 23 24 25 26 27 28 29
    30 31 32 33 34 35 36 37
    38 39 40 41 42 43 44
    45 46 47 48 49 50
    51 52 53 54 55
    56 57 58 59
    60 61 62
    63 64
    65​
    Reply
    • adi says

      June 12, 2021 at 10:32 pm

      #Here is the solution for your question

      
      q = int(input())  # q = 11 
      n = int(input())  #n = 10 
      i = 1
      p = q
      while(i<=n):
             j = 1 
            while(j<=n-i+1):
                   print(p,end=" ")
                   p=p+1 
                   j=j+1 
            print()
            i=i+1 
      Reply
      • keta vora says

        October 3, 2022 at 6:00 pm

        4 3 2 1
        3 4 3 2 
        2 3 4 3
        1 2 3 4
        Reply
  73. Ammar says

    February 16, 2021 at 11:33 am

    kindly solve this

    *
    
    *   **
    
    *   **   ****
    
    *   **   ****   ********
    
    *   **   ****   ********   ****************
    Reply
  74. Ammar says

    February 16, 2021 at 11:29 am

    A
    A   AA
    A   AA   AAAA
    A   AA   AAAA   AAAAAAAA
    A   AA   AAAA   AAAAAAAA   AAAAAAAAAAAAAAAA
    Reply
  75. Lucky Bawa says

    February 4, 2021 at 9:28 pm

    Can you please help me with this pattern

    1    2    3   4   5    6    7     8     9
    10 11 12 13        14  15  16  17
    18 19 20                      21 22 23
    24 25                                26 27
    28                                           29
    Reply
  76. Snehal says

    January 6, 2021 at 9:15 pm

    Hey Vishal,
    My self Snehal. I have been following your pynative work for almost a year now.
    I am a beginner at Python. I sometimes get stuck. I need questions to practice as well.

    You are helping me with this. Especially with patterns. I wanted to try nested for but I didn’t know how to practice. I got it now.

    Thank you so much.

    Reply
    • Vishal says

      January 7, 2021 at 10:05 am

      I am glad it helped you Snehal.

      Reply
  77. SRI KAMESWARI says

    November 29, 2020 at 10:14 am

    ****
    
    * *
    
    * *
    
    ****
    Reply
  78. Benjamin Odobasic says

    November 18, 2020 at 12:57 am

    can you draw this in python with for loops

    0 - - - - - - - 1
    - 2 - - - - - 3 -
    - - 4 - - - 5 - -
    - - - 6 - 7 - - -
    - - - - 8 - - - -
    - - - 9 - 0 - - -
    - - 1 - - - 2 - -
    - 3 - - - - - 4 -
    5 - - - - - - - 6
    Reply
  79. Achraf Ghaleb says

    November 3, 2020 at 6:13 pm

    Please, can you help me to print this pattern :

            *
        ####*####
    ########*########
        ####*####
            *

    I tested different methods but I can’t have exactly the same pattern
    if possible, I need a code with for and while loop

    I’m a beginner in Python, so I need more methods for learning

    thank you very much

    Reply
  80. Shreya says

    October 24, 2020 at 11:24 am

               1
            2 3 2
         3 4 5 4 3 
      4 5 6 7 6 5 4
    5 6 7 8 9 8 7 6 5
    

    How to print this pattern?

    Reply
  81. Priyanka says

    October 19, 2020 at 10:20 am

    Reverse triangle to get a result like

    9 8 7
    6 5
    4 3
    Reply
  82. Abhishek K Gautam says

    October 19, 2020 at 12:50 am

    2 loops were never really needed.

    for i in range(5):
        print(str(i+1)*(i+1))
    for i in reversed(range(5)):
        print(str(i+1)*(i+1))
    row=5
    for i in range(row):
        print(str(i+1)*(row-i))
    row=5
    for i in range(row):
        print(str(row)*(row-i))
    Reply
  83. REVATHY DHAKSHNAMOORTHY says

    October 16, 2020 at 9:04 am

    Kindly help with the below pattern
    Sample Input 1:
    5
    Sample Output 1:

    ####*++++
    ###***+++
    ##*****++
    #*******+
    *********
    Reply
    • Abhishek K Gautam says

      October 19, 2020 at 12:57 am

      total=9
      for i in reversed(range(4)):
          i+=1
          j=total-(2*i)
          print('#'*i+'*'*j+'+'*i)
      Reply
  84. Ankit Kumar says

    October 8, 2020 at 1:37 pm

    How to write this pattern in python?

    1
    2 1 2
    3 2 1 2 3
    4 3 2 1 2 3 4
    3 2 1 2 3
    2 1 2
    1
    
    Reply
  85. Nimesh says

    October 8, 2020 at 12:29 pm

    Enter the number of Rows:6

    ************
    *****   *****
    ****      **** 
    ***         ***
    **            **
    *               *
    
    Reply
  86. sami says

    October 3, 2020 at 8:39 am

    Somebody please help me to print this shape. Thanks

    *
    *.
    *.*
    *.*.
    *.*.*
    
    Reply
  87. Ferdinand says

    September 10, 2020 at 2:08 am

    Write a program that prompts the user for an integer n, and then prints the drawing as shown in the run examples. The drawing is made up of n bars, where the length of the first bar is 1, the second 2, …., n. The maximum possible value of n will be 9.

    3
    2 3
    1 2 3
    Reply
  88. MPA says

    September 9, 2020 at 7:22 pm

    Wonderful supportive programs to understand the fundamentals of Python coding!

    Reply
  89. Vash says

    September 2, 2020 at 2:02 pm

       | | + | |
        | + + |
          + + +
           + + 
            +
    
            +
          +  +
       |+  +  +|
      | |+  +|  |
     | | |+|  |  |
    | | ||| |  |  |    
    

    Any Idea How to Do this?

    Reply
  90. JUGANTA says

    August 31, 2020 at 5:50 pm

    HELP, Please print the following pattern as it is in python

    *
    *  *  *
    *  *  *  *  *
    *  *  *  *  *  *  *
    *  *  *  *  *  *  *  *  *
                    *  *  *  *  *
                    *  *  *  *  *
                    *  *  *  *  *
                     *  *  *  *  *
    Reply
  91. Juganta says

    August 31, 2020 at 5:44 pm

    PLEASE HELP FOR THIS CODE.Uegent please, Write a program in PYTHON to calculate the parking charges of a vehicle. Enter the type of vehicle as a character (like c for car, b for bus, etc.) and read the hours and minutes when the vehicle enters the parking lot. When the vehicle is leaving, enters its leaving time. Calculate the difference between the two timings to calculate the number of hours and minutes for which the vehicle was parked. Calculate the charges based on the following information:

    Vehicle Name Rate till 3 hours Rate after 3 hours
    Truck / bus Rs 20 30
    Car Rs 10 20
    Scooter /cycle/ Motor cycle Rs 5 10

    Reply
  92. Prabhdeep says

    August 15, 2020 at 7:58 am

    Can anyone help me to print below pattern

    *
    ***
    ******
    *********
    ******
    ***
    *
    Reply
    • Chikki says

      August 20, 2020 at 11:13 pm

      num = 7
      for i in range(1,num+1,2):
          print('*'*(i))
      for j in range(num-2,0,2):
          print('*'*(j))
      Reply
    • Sidhartha MS says

      September 11, 2020 at 9:59 am

      for j in range(4):
        print('*\t'*j)
      for j in range(2,0,-1):
        print('*\t'*j)

      Will print the same cane the values

      Reply
    • Tauqeer Ahmad says

      September 25, 2020 at 11:25 am

      n=4
      for i in range(n):
         print("*"*i)
      for i in range(n,0,-1):
         print("*"*i)
      Reply
    • abhishek says

      October 1, 2020 at 6:45 pm

      n=int(input('Enter the no of * u need'))
      for i in range(0, n):
          for j in range(0, i + 1):
              print("*", end=' ')
          print()
      
      for i in range(n
                     , 0, -1):
          for j in range(0, i - 1):
              print("*", end=' ')
          print()
      Reply
  93. Rutuja says

    August 5, 2020 at 5:42 pm

    1 4

    2 3

    2 3

    1 4
    Hello can you help me with this code please??

    Reply
  94. roshnai says

    July 26, 2020 at 2:30 am

    hi!
    your site is really very helpful!
    i have a question,
    can you please tell me that why in 17th question did you use a in range of (i) and then you printed a space?? see because i have value from 0 to 6 and if we use this later after printing “j”, what happens to 4 and 5th value of i? like where does this space will be included

    Reply
  95. Maruti says

    July 17, 2020 at 12:18 am

    1
    1 2
    1 3
    1 4
    1 2 3 4 5

    Can you write this program ?

    Reply
  96. nv says

    July 15, 2020 at 3:47 pm

    how to print this pattern in python that accepts no of rows to be printed as input

    1   2   3   4   5
         2   3   4   5
              3   4    5
                   4    5
                         5
    Reply
  97. sneha says

    July 6, 2020 at 7:22 am

    1
    1 2 1
    1 2 1 3 1 2 1
    1 2 1 3 1 2 1 4 1 2 1 3 1 2 1

    can anyone help me to print this pattern for 1st 2nd and nth input terms?

    Reply
    • Nk says

      August 4, 2020 at 1:40 pm

      1
      121
      12321
      1234321
      123454321
      1234321
      12321
      121
      1
      Reply
  98. shanthi says

    June 29, 2020 at 10:30 am

    CSK
    
    CCSSKK
    
    CCCSSSKKK
    
    CCCCSSSSKKKK

    please tell me how to print this pattern

    Reply
    • Gujjar Mohan Manjunath says

      July 6, 2020 at 8:19 pm

      st=’CSK’

      
      for i in range (n):
          m=''
          for x in st:
               for j in range(i):
                     m=m+x
           print(m)
      Reply
    • s k shivam says

      June 23, 2021 at 4:19 pm

      A
      AB
      ABC
      ABCD
      ABCDE

      provide the codes for printing as above (input will be no. of row)

      Reply
      • Halfside says

        August 19, 2022 at 11:17 pm

        word="ABCDE"
        x=" "
        For I in word:
              x+=I
              print(x)
        Reply
  99. saman says

    June 13, 2020 at 7:27 pm

    The output for the first solution is not correct.
    the output from the code:

     
    1  
    2 2  
    3 3 3  
    4 4 4 4  
    

    the desired output:

    1 
    2 2 
    3 3 3 
    4 4 4 4 
    5 5 5 5 5
    
    Reply
    • Sai Kiran says

      June 28, 2020 at 12:11 pm

      Can I get a solution to print this pattern?

             1
           232
         34543
       4567654
      567898765
      Reply
    • sathish reddy says

      July 3, 2020 at 7:19 pm

      
      rows=5
      for i in range(1,n+1):
             for j in range(1,i+1):
                    print(j,end="")
             print()
      Reply
    • Sara says

      July 5, 2020 at 12:04 am

      please notice that if we write range(1,6) that means it will include 1,2,3,4,5 but not 6.so if you want loop to be executed 5 times you have 2 options
      range(0,5)
      or range(1,6)

      Reply
    • Arpit says

      August 13, 2020 at 3:58 pm

      for i in range(1,6):
         for j in range (1,i):
          print ("*",end='')
      Reply
  100. Maulik says

    June 10, 2020 at 12:43 pm

    How to print.
    1
    23
    456
    78910

    Reply
    • Vishal says

      June 13, 2020 at 10:53 am

      Hey, Please find below the solution

      currentNumber = 1
      stop = 2
      rows = 4  # Rows you want in your pattern
      
      for i in range(rows):
          for column in range(1, stop):
              print(currentNumber, end=' ')
              currentNumber += 1
          print("")
          stop += 1
      
      Reply
      • Hinata Uzamaki says

        June 19, 2021 at 4:06 pm

         
        n = int(input()) 
        o = 1
        for i in range(1,n+1):
            for j in range(1,i+1,1):
                print(o,end=" ")
                o=o+1
            print()
        Reply
  101. Santosh Thengdi says

    May 30, 2020 at 10:43 pm

    Generating Binomial Distribution
    Description
    Generate a binomial distribution, tested 10 times, given the number of trials(n) and probability(p) of each trial.

    The input will contain seed, n, and p in the same order.

    The output should contain a numpy array with 10 numbers representing the required binomial distribution.

    Hint: You can use numpy’s random number generator here too. Remember to set the seed before generating numbers to ensure the correct output.

    Sample Input:

    0

    10

    0.5

    Sample Output:
    [5 6 5 5 5 6 5 7 8 5]

    Reply
  102. Saily says

    May 30, 2020 at 2:05 pm

    Hello Vishal. I loved your article. I have been struggling with pattern printing questions since some time. Your simple coding steps and explanation in the begining of article has helped me alot. Thanx a lot for the compilation of the pattern printing questions. Great job!!

    Reply
    • Vishal says

      May 31, 2020 at 11:17 am

      You are welcome, Saily.

      Reply
  103. phudki says

    May 11, 2020 at 11:53 pm

    1
    2 1
    3 2 1
    4 3 2 1
    5 4 3 2 1
    6 5 4 3 2 1

    How can I print the below pattern with loops?

    Reply
    • Kaushik says

      June 5, 2020 at 3:28 pm

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

        June 5, 2020 at 3:32 pm

        Above code is for the question asked by phudki

        Reply
  104. Bilal ansari says

    May 2, 2020 at 5:41 pm

    i need output for the following pattern:

          *
       * # *
    * # #  *
    

    please do this needful..

    Reply
  105. Kamaljit says

    April 27, 2020 at 11:56 am

    1 *
    2 * *
    3 * * *
    4 * * * * 
    

    Please print code for this

    Reply
    • AZIZ KANCHWALA says

      May 13, 2020 at 2:24 pm

      rows=4
      for i in range(1,rows+1):
          for j in range(i+1):
              if j==0:
                  print(i,end=' ')
              else:
                  print('*',end=' ')
          print('\r')
      
      Reply
    • xyz says

      July 18, 2020 at 2:56 pm

      num=int(input("Enter number of rows: "))
      for i in range(1,num+1):
          print(i,end=' ')
          for j in range(1,i+1):
              print("* ",end=' ')
          print()
      Reply
    • abhi says

      September 27, 2022 at 11:02 am

      5432*
      543*1
      54*21
      5*321
      *4321

      Print this?

      Reply
  106. uuu says

    April 27, 2020 at 6:49 am

                                    1
    			2	2
    		3	3	3
    	4	4	4	4
    5	5	5	5	5
    

    code for this?

    Reply
    • kaushik says

      June 5, 2020 at 4:27 pm

      rows = int(input("Enter number of rows: "))
      for i in range(0,rows):
          for j in range(0,rows):
              if(j<rows-i-1):
                  print(" ",end=" ")
              else:
                  print(i+1,end=" ")
          print()
      

      #This code is for the question asked by uuu

      Reply
  107. love of my life says

    April 19, 2020 at 12:08 pm

    How to print this using a while loop?

    PPPP#
    PPP###
    PP#####
    P#######
    #########
    P#######
    PP#####
    PPP###
    PPPP#
    
    Reply
    • A A A says

      May 8, 2020 at 2:08 pm

      print the following number triangle using while loop

      5 6 7 8 9
      2 3 4
      1
      2 3 4
      5 6 7 8 9
      
      Reply
  108. Bharath says

    April 18, 2020 at 6:29 pm

    Could you please try a diamond pattern in which the stars(‘*’) will have 2 pyramids mounted on each other’s base

    Reply
    • Vishal says

      April 19, 2020 at 8:30 pm

      Yes. I will add

      Reply
      • Manali says

        April 8, 2022 at 12:29 pm

        Hii
        Please help me with this pattern

        7
        6 6
        14 14 14
        12 12 12 12
        21 21 21 21 21
        Reply
    • Aayush says

      April 25, 2020 at 5:21 pm

      def pattern(n):
          k = n - 1
          for i in range(0, n):
              for j in range(0, k):
                  print(end=" ")
              k = k - 1
              for j in range(0, i + 1):
                  print('*  ', end="")
              print('\r')
      pattern(5)
      
      Reply
  109. san T says

    April 18, 2020 at 1:33 am

    How to print below pattern:-

    4444444
    4333334
    4322234
    4321234
    4322234
    4333334
    4444444
    
    Reply
    • Ram says

      June 26, 2020 at 10:31 pm

      
      def pattern(n):
          k = 2 * n - 2
          x = 0
          for i in range(0, n):
              x += 1
              for j in range(0, k):
                  print(end=" ")
              k = k - 1
              for j in range(0, i + 1):
                  print(x, end=" ")
              print(" ")
          k = n - 2
          x = n + 2
          for i in range(n, -1, -1):
              x -= 1
              for j in range(k, 0, -1):
                  print(end=" ")
              k = k + 1
              for j in range(0, i + 1):
                  print(x, end=" ")
              print(" ")
      Reply
    • shubham sachdeva says

      October 27, 2020 at 4:14 pm

       
      n = int(input())
      temp = n 
      
      for i in range(1,n+1):
          for j in range(1,i,1):
              for x in range(1,i,2*i):
                  print(n-j+1,end="")
          for k in range(2*n - 2*i+2,1,-1):
              print(temp,end="")
          temp = temp -1
          for j in range(i,1,-1):
              for x in range(1,i,2*i):
                  print(n-j+2,end="")
          print()
          
      temp = 2 
      for i in range(n,1,-1):
          for j in range(2,i,1):
              print(n-j+2,end="")
          for k in range(2*n-i,i-3,-1):
              print(temp, end="")
          for x in range(i-1,1,-1):
              print(n-x+2,end="")
          temp = temp+1
          print()
      Reply
  110. Rabia says

    January 6, 2020 at 8:52 pm

    How can I print this
    write a program that inputs the number of rows and print this

     
    1*2*3
    1*2
    1
    
    Reply
    • Awan says

      January 16, 2020 at 12:17 am

      don’t know

      Reply
      • Santosh Thengdi says

        April 19, 2020 at 11:40 am

        I am not asking you..Please don’t waste your word unnecessary.

        Reply
    • naga kalyan says

      March 24, 2020 at 8:07 am

      a=int(input())
      for i in range(0,a):
          c=1
          print(c,end=' ')
          for j in range(a-i-1,0,-1):
              print('*',end=' ')
              c=c+1
              print(c,end=' ')
          print('\n')
      
      Reply
    • pawan mehra says

      June 4, 2020 at 4:07 pm

      use end="*" in print

      Reply
  111. stavros says

    December 27, 2019 at 9:02 pm

    --**
    -****
    ******
    -*---*-
    

    Code for this, please??
    for N=3
    How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.
    or for N=4

    ---**
    --****
    -******
    ********
    -*----*
    
    Reply
  112. steven says

    December 27, 2019 at 3:41 am

    for N=3
    How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.

        **
      ****
    ******
     *     *
    
    Reply
    • Abhi Mestri says

      January 24, 2020 at 2:52 pm

      Code for this Pattern

      1
      1 1 
      1 1 2 
      1 1 2 3 
      1 1 2 3 5
      
      Reply
      • Yamini says

        March 12, 2020 at 5:11 am

        Coding for this one

        C
        CO
        COM
        COMP
        COMPU
        COMPUT
        COMPUTE
        COMPUTER
        
        Reply
        • shyam says

          March 20, 2020 at 1:57 pm

          a=input("enter the word")   
          b=""                                         
          for i in a:                                     
              b=b+i
              print(b)
          
          Reply
        • Tasleem says

          July 6, 2020 at 12:53 am

          ?

          Reply
        • n k shivam says

          June 23, 2021 at 4:24 pm

          word = "COMPUTER"
          x = ""
          for i in word:
              x += i
              print(x)
          Reply
  113. steven says

    December 27, 2019 at 3:35 am

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

    How to build an N height pyramid (N=3) with 2 stars at the top and 2 stars for feet for the second and penultimate columns.

    Reply
  114. Poornima Rani says

    December 24, 2019 at 2:36 pm

    how do I print

    *
    *-*
    *----*
    *-*
    *
    
    Reply
  115. Amit Korde says

    September 18, 2019 at 5:47 pm

    11111
    2222
    333
    44
    5

    Code for this?

    Reply
    • Sayantan Poddar says

      December 2, 2019 at 2:25 am

      How to print this?

      1
      121
      12321
      1234321
      
      Reply
      • hari krishna kothapalli says

        February 29, 2020 at 1:50 am

        n=int(input("enter no of rows:"))
        for i in range(1,n+1):
            for j in range(1,i-1):
                print(j,end="")
            for j in range(i-1,0,-1):
                print(j,end="")
            print()
        
        Reply
        • hari krishna kothapalli says

          February 29, 2020 at 1:54 am

          make sure to use the identation

          Reply
    • Himanshu chaturvedi says

      December 18, 2019 at 8:36 pm

      How to print this pattern

      8
      86
      864
      8642
      
      Reply
      • Nagesh J says

        April 2, 2020 at 5:48 pm

        counter=2
         a='8'
         b=a
        for i in range(5):
          print(b)
          b = b+chr(ord(a)-counter)
          counter = counter+2
        

        .
        Output below is

        8
        86
        864
        8642
        86420
        
        Reply
    • shyam says

      March 20, 2020 at 2:07 pm

      a=int(input("enter your no"))
      b=0
      for i in range(a,0,-1):
          b=b+1
          for j in range(1,i+1):
              print(b,end='')
          print('\n')
      
      Reply
  116. Rohit Kumar Setthachok says

    September 6, 2019 at 6:11 pm

    How to write a program that prints out the triangle of star(s) depending on the input,
    n, by follow the pattern in the following samples using while-loop
    Sample Run#2

    n: 2
    *
    ***
    Sample Run#3
    n: 5
    *
    ***
    *****
    *******
    *********
    
    Reply
    • tej says

      December 17, 2019 at 3:10 pm

      n=int(input())
      for i in range(1,n+n):
             for j in range(1,i+1):
                     i=i%2!=0
                      print('*'*i,end='  ')
             print()
      
      Reply
      • Tasleem says

        July 6, 2020 at 12:54 am

        ?

        Reply
  117. Jack says

    September 6, 2019 at 1:52 pm

    How do I print out

    ####################
    #########--#########
    ########----########
    #######------#######
    ######--------######
    #####----------#####
    ####------------####
    ###--------------###
    ##----------------##
    #------------------#
    

    as well as

    0 ##########
    1 #########-
    2 ########--
    3 #######---
    4 ######----
    5 #####-----
    6 ####------
    7 ###-------
    8 ##--------
    9 #---------
    

    Thank you

    Reply
    • siddharth says

      September 7, 2019 at 9:11 pm

      a=20 # or  a=int(input()) if it  is a user input question
      print("#"*a,end="\n") #its the first line of pattern
      i=(a//2)-1
      j=2
      while(i!=0):
          while(j<=(a-2)):
              print("#"*i,end="")
              print("_"*j,end="")
              print("#"*i,end="\n")
              i=i-1
              j=j+2
      

      hope this helps 🙂

      Reply
    • Nishant says

      December 24, 2019 at 7:19 pm

      How we can create continue pattern of rainfall effect using a diamond pattern
      Print must be like as

      1  2  3
        1   2
           1
      1  2  3
        1  2
      

      … continue
      Here 1 2 3 represent diamond has to print this type of manner

      Reply
  118. swetha says

    September 5, 2019 at 8:37 am

    8
    8 6
    8 6 4
    8 6 4 2
    
    Reply
  119. manoj says

    August 25, 2019 at 11:32 am

    how will we print

    4444
    444
    44
    4
    
    Reply
  120. pratiksha bhabad says

    August 24, 2019 at 4:54 pm

    how to print

    5 4 3 2 1
    4  3 2 1
    3 2 1
    2 1
    1
    
    Reply
    • Anupam Sharma says

      February 9, 2020 at 1:37 am

      n = 5
      k = 5
      for i in range(0,n+1):
          for j in range(k-i,0,-1):
              print(j,end=' ')    
          print()
      
      Reply
  121. HD says

    August 10, 2019 at 7:58 pm

    1  2   3   4   5
    2  4 12 48 
    3 12 144  
    4 48
    5
    

    Someone solves this…

    Reply
    • naga kalyan says

      March 24, 2020 at 9:32 am

      a=int(input())
      l1=[*range(1,a+1)]
      for i in range(1,a+1):
          for j in range(a,i-1,-1):
              if(i==1):
                  print(l1[a-j],end=' ')
              elif(j==a):
                  l1[a-j]=i
                  print(l1[a-j],end=' ')
              else:
                  l1[a-j]=l1[a-j]*l1[a-j-1]
                  print(l1[a-j],end=' ')
          print()
      
      Reply
  122. surbhi says

    August 2, 2019 at 2:50 pm

    we cant understand this reply… please write program in simple pl.

    Reply
  123. Alina says

    July 23, 2019 at 9:39 pm

    How to print this?

    0
    0    1
    0    2    4
    0    3    6    9
    0    4    8  12  16
    0    5  10  15  20  25
    0    6  12  18  24  30  36
    
    Reply
    • naga kalyan says

      April 13, 2020 at 9:34 am

      a=int(input())
      for i in range(0,a):
          for j in range(0,i+1):
              print(i*j,end=' ')
          print()
      
      Reply
  124. Angikar Roy Chowdhury says

    July 22, 2019 at 10:56 pm

    Code for this?
    1 2 3 4
    2 3 4
    3 4
    4

    Reply
    • Abhijeet says

      April 7, 2020 at 10:04 am

      n = int(input())
      i = i + 1
      for i in range(0,n+1,1):
              for j in range(i+1,n+1,1):
                  print(j,end='')
              print()
      
      Reply
  125. Anurag says

    July 14, 2019 at 8:00 am

    1

        3*2
        4 *5 *6
        10 *9 *8 *7
    

    please give an answer for this output

    Reply
  126. Divya says

    July 12, 2019 at 8:26 pm

    * * * *
    * * *
    * *
    *

    Reply
  127. Diya punetha says

    July 12, 2019 at 8:18 pm

    * * * *
    * * *
    * *
    *

    Reply
    • Anurag says

      July 14, 2019 at 8:07 am

      for i in range(0,4):
          for j in range(4-i):
              print("*", end="")
          print("\n")
      
      Reply
      • yash says

        August 18, 2019 at 1:12 pm

        it gives an invalid syntax error to the equals to sign in every such code for printing patterns…

        Reply
  128. Diya punetha says

    July 12, 2019 at 8:16 pm

    * * * *
    * * *
    * *
    *
    How to do this

    Reply
  129. irtaja says

    July 12, 2019 at 12:56 am

    how to print this like
    *
    **
    ***
    ****

    Reply
    • Diya punetha says

      July 12, 2019 at 8:22 pm

      for i in range(1, 5) :
             for j in range(i) :
                   print "*", 
             print
      
      Reply
    • Jacinta says

      February 4, 2020 at 6:43 pm

      for i in range (0,4):
         for j in range (0,I+1):
             Print ("*" , end="")
          print()
      
      Reply
  130. Priyaranjan says

    July 11, 2019 at 8:48 pm

    how to print

    1
    2 9 
    3 8 10 
    4 7 11 14
    5 6 12 13 15
    
    Reply
  131. hassan708 says

    July 7, 2019 at 3:23 am

    receives an integer n as a parameter and displays a pattern of stars on the screen

    stars(2);
    ****
    **
    stars(3);
    *********
    ******
    ***
    stars(4);
    ****************
    ************
    ********
    ****
    
    Reply
    • naga kalyan says

      April 13, 2020 at 9:41 am

      a=int(input())
      for j in reversed(range(1,a+1)):
          print('*'*(a*j))
      
      Reply
    • Sanjay says

      August 17, 2021 at 4:57 pm

      if I give input like 5,2,3

      output like

           /
      / \ /
      / \ /
      /
      /
      /
      /
      Reply
  132. Taufique says

    July 6, 2019 at 9:32 am

    5 4 3 2 1 1 2 3 4 5
    5 4 3 2        2 3 4 5
    5 4 3               3 4 5
    5 4                       4 5
    5                              5
    

    Please help me to solve this

    Reply
    • Manoj says

      September 8, 2019 at 12:55 am

      for i in range(0,6):
          for j in range(5,i,-1):
              print(j,'',end='')
          for l in range(i):
              print('        ',end='')
          for k in range(i+1,6):
              print(k,'',end='')
          print('\n')
      
      Reply
    • Himanshu chaturvedi says

      December 18, 2019 at 8:41 pm

      Please tell me the program of these outputs:

      8
      86
      864
      8642
      86420
      
      Reply
  133. sanjeev shukla says

    July 2, 2019 at 7:43 pm

    1, 1, 2, 4, 4, 8, 8, 16, 16, upto n numbers,
    how to print this?

    Reply
  134. ABDULBASIT says

    July 1, 2019 at 9:06 pm

    for j in range(0, i + 1):
    how code actually works
    in pyramid

    Reply
  135. Subham Roy says

    July 1, 2019 at 12:10 pm

    1
    33
    555
    7777
    99999
    print the above pattern !

    Reply
    • Ghanshyam says

      September 7, 2019 at 7:59 pm

      print("Enter Limit: ")
      n = int(input())
      i = 1
      while(i<=n):
          j = 1
          while(j<=i):
              print((i*2-1), end="")
              j  = j + 1
          i = i + 1
          print()
      
      Reply
  136. Shivam Bhirud says

    June 28, 2019 at 10:22 pm

    I have a better code with O(n) complexity to print the pattern given below-

    * 
    * * 
    * * * 
    * * * * 
    * * * * * 
    
    code-
    
    n = 5
    for j in range(1,n+1):
        print("* " * j)
    
    Reply
  137. Vaibhav Vinsmoke says

    June 14, 2019 at 12:42 am

    1 2 3 4 5
    2 2 3 4 5
    3 3 3 4 5
    4 4 4 4 5
    5 5 5 5 5
    

    how do i print this one?

    Reply
    • Ghanshyam says

      September 7, 2019 at 8:10 pm

      print("Enter limit: ")
      n = int(input())
      i  = 1
      while(i <= n):
          j = 1
          while (j = j):
                  print(format(i, "2d"), end=' ')
              else:
                  print(format(j, "2d"), end=' ')
              j = j + 1
          print()
          i = i + 1
      
      Reply
  138. Vaibhav Vinsmoke says

    June 14, 2019 at 12:36 am

    12345
    22345
    33345
    44445
    55555

    how do i print this one?

    Reply
    • naga kalyan says

      April 13, 2020 at 9:45 am

      a=int(input())
      for i in range(1,a+1):
          for j in range(1,a+1):
              if(j<=i):
                  print(i,end=' ')
              else:
                  print(j,end=' ')
          print()
      
      Reply
  139. Dishank Rastogi says

    June 10, 2019 at 4:59 pm

    1                1
    12            21
    123        321
    1234    4321
    1234554321
    

    how to print this?

    Reply
    • yash Boomerang dev says

      June 14, 2019 at 12:40 am

      its pretty simple….
      take your code editor and ask someone to do this for you and take the credit.
      after writing the code press run or f5 then itll be printed.

      Reply
  140. sumana says

    June 2, 2019 at 8:58 pm

    1
        1  2  1
    1  2  3  2 1
        1  2  1
            1
    

    please help me to write “”bottom part of this diamond of numbers””

    Reply
  141. Prema says

    May 23, 2019 at 12:10 pm

    1
             1 2
          1 2 3
       1 2 3 4 
    1 2 3 4 5 
    

    Please Solve this number pattern 9in Python

    Reply
  142. Rohith says

    May 22, 2019 at 6:40 pm

            * 
           * * 
          * * * 
         * * * * 
        * * * * *
    
    
        * * * * * 
         * * * *
          * * *
           * *
            *
    
    
    Reply
    • priyanka says

      December 21, 2019 at 1:47 pm

      I need program for your pattern please

      Reply
  143. Rohith says

    May 22, 2019 at 6:35 pm

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

    pls help some bady

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

    Reply
    • Muhammad Bilal says

      March 5, 2020 at 1:12 pm

      i also need it….plz if anyone can help.

      Reply
      • Archana Allishe says

        May 3, 2020 at 10:44 am

        num = 5
        for row in range(num)
            print("*   " *(row+1))
        for row in range(num):
            print("*   " *(num-row))
        
        Reply
        • Archana Allishe says

          May 3, 2020 at 10:50 am

          num = 5
          for row in range(num):
             print("* "*(row+1))
          for row in range(num):
             print("* "*(num-row))
          
          Reply
    • rima alloush says

      October 3, 2020 at 4:12 am

      num=4
      for i in range(0,num):
          for j in range(0,num-i-1):
              print(end="")
          for j in range(0,i+1):
              print("*",end=" ")
          print()
      Reply
  144. Anju sebastian says

    May 18, 2019 at 4:58 pm

    1 
    2     2 
    3     3     3 
    4    4    4    4
    

    program for this ?

    Reply
    • prema says

      May 23, 2019 at 12:11 pm

      for i in range(1,6):
          for j in range (1,6):
              if j<=i:
                  print(i,end='')
          print()
      
      Reply
    • M.AJAY KUMAR says

      June 10, 2019 at 11:21 pm

      n=int(input("enter a number:"))
      for i in range (1,n+1):
           for j in range(1,i+1):
              print(i,end=" ")
           print( )
      
      Reply
    • Uday Garg says

      February 11, 2020 at 5:11 pm

      row = 5
          for i in range(row):
              for j in range(0, i):
                  print(i, end="")
      
              print("\n")
      
      Reply
  145. Myrna says

    May 18, 2019 at 7:49 am

    how do I print this

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

    Reply
    • Nar Hari Gautam says

      August 1, 2020 at 4:00 pm

      for row in range(6):
          for col in range(5):
              if (row==0 or row==5 and col!=0):
                  print("*",end="")
              elif(col==0):
                  print("*",end="")
              else:
                  print(end="")
                  
          print()
      Reply
  146. Anju says

    May 17, 2019 at 11:04 am

    Program for this output Write a program to print the following  pattern: 

                   1
               2     2 
           3     3     3 
         4    4    4    4
    
    Reply
  147. Jackson says

    May 14, 2019 at 1:22 am

    *******O** 
    ******O*** 
    ******O*** 
    *O******** 
    *****O****
    

    How do make this 5 * 10 grid by using random function and each row have only one ‘O’ and the position are random?

    Reply
  148. Ronak Jain says

    May 13, 2019 at 3:59 pm

    1 2 3 4 5 6 7 8 9
    **2 3 4 5 6 7 8
    ****3 4 5 6 7
    ******4 5 6
    ********5
    

    what is the code for this pattern in python

    Reply
  149. Ronak Jain says

    May 13, 2019 at 3:51 pm

    1 2 3 4 5 6 7 8 9
       2 3 4 5 6 7 8
          3 4 5 6 7
             4 5 6
                5
    

    what is the code for this pattern in python

    Reply
    • naga kalyan says

      April 13, 2020 at 10:03 am

      a=int(input())
      for i in range(1,a+1):
          for j in range(1,(a*2)-i+1):
              if(j<i):
                  print('*',end='*')
              else:
                  print(j,end=' ')
          print()
      
      Reply
  150. hanisah says

    May 5, 2019 at 12:44 pm

    How to get this?

    Input number : 3 
    Expected Output : 

           *
         *   *
       *       *
    
    Reply
    • Shivam Srivastava says

      May 7, 2019 at 4:48 pm

      for i in range(1,n+1):
          for j in range(1):
              if i==1:
                  print(i*"*",end="")
              else:
                  print(2*"*",end="")
          print()
      
      Reply
  151. vishal karnawat says

    May 4, 2019 at 5:08 pm

    10000
    01000
    00100
    00010
    00001
    

    create the following pattern

    Reply
    • Shivam Srivastava says

      May 7, 2019 at 4:38 pm

      n=5
      for i in range(n):
          for j in range(n):
              if j==i:
                  print("1",end="")
              else:
                  print("0",end="")
          print()
      
      Reply
  152. Adarsh says

    May 2, 2019 at 3:03 pm

    Plz print this pattern its. Urjent

    *
    ***
    *****
    *******
    *********
    
    Reply
    • Shivam Srivastava says

      May 7, 2019 at 4:35 pm

      n=5
      for i in range(n):
          for j in range(i+1):
              print("*",end="")
          print()
      
      Reply
    • Shivam Srivastava says

      May 7, 2019 at 4:44 pm

      n=5
      for i in range(1,n+1):
          for j in range(1):
              print((2*i-1)*"*",end="")
          print()
      
      Reply
  153. Shazan Hussain says

    April 12, 2019 at 6:28 am

    -*******
    --******
    ---*****
    ----****
    -----***
    ------**
    -------+
    

    plz kindly tell me how to make this?

    Reply
    • Muhammad Bilal says

      March 5, 2020 at 1:14 pm

      i need it urgently..

      Reply
    • Muhammad Bilal says

      March 5, 2020 at 1:34 pm

      rows = input("Enter number of rows ")
      rows = int (rows)
      for i in range (rows, 0, -1): 
          print((rows-i) * ' ' + i * '*')
      
      Reply
  154. asenluke says

    April 11, 2019 at 6:54 pm

    How can I print this? has to work on Adhesive python
    THIRD

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

    Here is the basis code to use:

    for i in range(3):
       for j in range(3-i):
           print("*", end=" ")
       print("")
    
    Reply
  155. Mario says

    April 2, 2019 at 10:55 pm

    Write a program that uses nested loops to draw this pattern:

    1	0	0	0
    0	1	0	0
    0	0	1	0
    0	0	0	1
    
    Reply
  156. Mario says

    April 2, 2019 at 10:40 pm

    Write a program that uses nested loops to draw this pattern:

    A
    B	B
    C	C	C
    D	D	D	D
    E	E	E	E	E
    F	F	F	F	F	F
    
    Reply
  157. deep says

    February 26, 2019 at 3:28 am

    Enter your age, then print that many stars (*) in one line

    Reply
  158. logesh says

    February 22, 2019 at 11:27 am

        *                                                                                                                            
       **                                                                                                                            
      ***                                                                                                                            
     ****                                                                                                                            
    *****                                                                                                                            
     ****                                                                                                                            
      ***                                                                                                                            
       **                                                                                                                            
        *
    
    Reply
  159. logesh says

    February 22, 2019 at 9:56 am

        *
       **
      ***
     ****
    *****
     ****
      ***
       **
        *
    
    Reply
  160. sven says

    February 20, 2019 at 5:40 am

                      1
                    232
                  34543
                4567654
              567898765
            67890109876
          7890123210987
        890123454321098
      90123456765432109
    0123456789876543210
    
    Reply
    • sven says

      February 20, 2019 at 5:42 am

      this is supposed to look like a tree. not like this. idk why this wasn’t spaced out

      Reply
  161. Rishabh says

    January 26, 2019 at 3:16 pm

    1
    10
    101
    1010
    10101
    
    Reply
    • subham subhasis says

      July 2, 2019 at 4:44 pm

      def pypart(n): 
      	for i in range(0, n): 
      		for j in range(0, i+1): 
      			if j % 2 == 1 :
      				print("0 ",end="") 
      			else :
      				print("1 ",end="") 
      		# ending line after each row 
      		print("\r") 
        
      # Driver Code 
      n = 5
      pypart(n)
      
      Reply
  162. Avarangi says

    January 26, 2019 at 10:30 am

    16 15 13 10
    14 12 9 6
    11 8 5 3 
    7 4 2 1
    

    Pattern for this!!!

    Reply
  163. Rishabh says

    January 21, 2019 at 11:33 pm

    1
    10
    101
    1010
    10101
    
    Reply
    • harsh says

      August 21, 2023 at 11:27 am

      x=1
      for y in range(0,5):
      for z in range(y+1):
      print(x%2,”,end=””)
      x+=1
      print()

      Reply
  164. Sohair says

    January 16, 2019 at 10:48 pm

    I have some question
    1. why we are using end = ‘ ‘? wht is the purpose of it.
    2. need explanation for 3rd argument in range() ex- rage(1, 11, -1)

    Reply
    • Vishal says

      January 16, 2019 at 11:33 pm

      Hi Sohair, end = ‘ ‘ used to have space between numbers or stars.
      For example, if we executing loop 5 times and in each iteration we are printing
      print("*", end=', ') this statemment. this will print *,*,*,*,*

      For second question range(11, 1, -1) this will print range in reverse order. i.e. 11, 10, 9....0 For better understanding on range function please refer to Python range() function

      Reply
  165. Pri says

    January 15, 2019 at 8:06 pm

    n=3

    @@@ @@@
    @@@***@
    @@@ @@@
    

    n=5

    @@@@@ @@@@
    @@@@@ @
    @@@@@*****@
    @@@@@ @
    @@@@@ @@@@@ 
    

    the print above pattern in python

    Reply
  166. Rohan says

    January 14, 2019 at 2:33 pm

    https://paste.pound-python.org/show/ABB0xOHlvRVauIaa6lpV/
    Need help with this.

    Reply
  167. hanzalah says

    January 13, 2019 at 8:31 pm

    sir, I want this program

    # * #  *  # * # * # 
       * # * # * # * #
          # * # * # * 
           * # * # * 
             # * #
               * #
                 #
    
    Reply
    • hanzalah says

      January 13, 2019 at 8:32 pm

      ais tarha ka patteren inverted pyramid form ma

      Reply
  168. Shashank says

    January 11, 2019 at 11:21 pm

    Please print below pattern

                      1  2
                    1  2  3
                  1  2  3  4
                1  2  3  4  5
    

    Help its urgent

    Reply
    • Vishal says

      January 12, 2019 at 8:43 am

      Hi Shashank its already there in examples please check

      Reply
      • Shashank says

        January 12, 2019 at 7:05 pm

        Sir I want full triangle pattern not right triangle pattern

        Reply
  169. ahmer says

    January 6, 2019 at 12:16 pm

    * * * *
      * * *
        * *
          *
    

    how will we do this??

    Reply
    • ahmer says

      January 6, 2019 at 12:17 pm

      ****
       *** 
        **
         *
      
      Reply
    • suryakanth says

      August 1, 2019 at 11:08 am

      for i in range(5):
      print(f"*" * (4-i))
      
      Reply
    • harish says

      September 26, 2024 at 2:56 pm

      n=4
      for i in range(n,0,-1):
      for j in range(n,0,-1):
      if i>=j:
      print(‘*’, end=’ ‘)
      else:
      print(‘ ‘, end=’ ‘)
      print(”)

      Reply
  170. Mary says

    January 2, 2019 at 11:21 pm

    Hello,

    How do you write this function using recursion?

    print("Program to print start pattern: \n");
    rows = input("Enter max star to be display on single line")
    rows = int (rows)
    for i in range (0, rows):
        for j in range(0, i + 1):
            print("*", end=' ')
        print("\r")
    for i in range (rows, 0, -1):
        for j in range(0, i -1):
            print("*", end=' ')
        print("\r")
    

    Thank you,
    Mary

    Reply
  171. kiruba says

    December 29, 2018 at 8:58 pm

    how to make this one!

    1 2 4 7
    3 5 8 11
    6 9 12 14
    10 13 15 16
    
    Reply
  172. Rahul Anand Singh says

    December 27, 2018 at 12:02 am

    ABCDEFGFEDCBA
    ABCDEF    FEDCBA
    ABCDE        EDCBA
    ABCD             DCBA
    ABC                   CBA
    AB                         BA
    A                               A
    
    Reply
  173. nnn says

    December 22, 2018 at 10:45 pm

    How can i do an input string to *

    Reply
    • Vishal says

      December 22, 2018 at 10:56 pm

      You can refer our article https://pynative.com/python-input-function-get-user-input/

      Reply
      • nnn says

        December 24, 2018 at 2:48 am

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

        Just like this but if we have any words like input

        Reply
  174. keat says

    December 22, 2018 at 1:43 pm

    hello everyone ,do you know how to display

    1 2 3
    4 5 6
    7 8 9
    
    Reply
    • gavin says

      March 2, 2019 at 11:57 am

      print("1 2 3")
      print("4 5 6")
      print("7 8 9")
      
      Reply
  175. jayti says

    December 11, 2018 at 7:59 pm

                  1
              2   2   2
         3   3   3   3   3
    4   4   4   4   4   4   4
    

    how do we make this one?

    Reply
    • MOHAMMAD MEHDI says

      April 25, 2019 at 3:14 am

      n=int(input("enter a number of row"))
      count=1
      for row in range(1,n+1):
              for col in range(1,row+count):
                  print(row,end="")
              count=count+1
              print()
      
      Reply
  176. MANISH BISHNOI says

    December 2, 2018 at 1:57 pm

    I NEED A PROGRAMME FOR THE FOLLOWING PATTERN

                                *
                            *  *
                       *   *  *
    
    Reply
    • Bharath says

      December 4, 2018 at 6:47 pm

      I need to program for the following pattern

      4 4 4 4
      4 3 3 3
      4 3 2 2
      4 3 2 1
      
      Reply
      • manivannan.v says

        July 1, 2019 at 1:17 pm

        for i in range(4):
          current=4
          increment=0
          for j in range(4):
            print(current-increment,end="")
            if(increment<i):
              increment=increment+1
          print()
        
        Reply
      • Nitish says

        May 8, 2020 at 1:29 am

        n = int(input())
        for i in range(1, n):
            num = n
            for j in range(1, n):
                print(num, end='')
                if i > j:
                    num-=1
        
            for j in range(n,n+1):
                print(n+1-i,end='')
            num=n
            for j in range(1,n):
                print(num+1-i,end='')
                if n-ij:
                    num-=1
            for j in range(n,n+1):
                print(i+1,end='')
            num=i+1
            for j in range(1,n):
                print(num,end='')
                if j>=i:
                    num+=1
            print()
        
        Reply
    • vishal gaddam says

      December 16, 2018 at 10:13 pm

      counter = 1
      while counter < 4:
            print(counter * "*")
            counter +=1
      
      Reply
  177. KISLAY CHANDAN says

    December 1, 2018 at 9:16 am

    hey, can anyone help me with this code? It must be done using for and if only.

                0
             1 0 1
          2 1 0 1 2
       3 2 1 0 1 2 3
    4 3 2 1 0 1 2 3 4
    

    I tired and think every stuff but I don’t understand what I am missing. I am having an issue with generating 101, 21012, 3210123, 43211234
    here is my code(which is wrong)

    for i in range (1,6):
        for t in range (i,5):
            print('\t', end="")
        for j in range (0,(2*i-1)):
            print(2*i-1-j, "\t", end="")
        print("")
    
    Reply
    • Eyal Mozhi says

      December 4, 2018 at 6:21 pm

      Can you please provide the exact output you need

      Reply
  178. Ryan says

    November 28, 2018 at 6:56 pm

    5 4 3 2 1 0 1 2 3 4 5 
    4 3 2 1 0 1 2 3 4
    3 2 1 0 1 2 3
    2 1 0 1 2
    1 0 1
    0
    

    How to get this pattern?

    Reply
  179. Axile28 says

    November 24, 2018 at 8:17 pm

    *
    **
    ***
    **
    *
    

    some help on this?

    Reply
    • Vishal says

      November 24, 2018 at 11:11 pm

      Hey Axile28. Please check Example 4: print Asterisk (Start) pattern

      Reply
    • Akshay Agrawal says

      March 14, 2019 at 6:13 pm

      n = int(input("enter a num"))
      i=1
      while i<=n :
          print("*"*i)
          i+=1
      j=1
      while j<=n :
          print("*"*(n-j))
          j+=1
      
      enter a num3
      *
      **
      ***
      **
      *
      
      Reply
  180. Babita says

    November 23, 2018 at 12:30 pm

    ####
     ####
       ####
     #### 
    ####
    
    Reply
    • vishal gaddam says

      December 16, 2018 at 10:11 pm

      for i in range(1,6):
      	print("####")
      
      Reply
      • Harsh Sinha says

        October 23, 2022 at 12:38 pm

        The code is wrong. A j loop is required for initial spaces.

        Reply
  181. Nanaki N Nasei says

    November 19, 2018 at 3:09 pm

     
        *
      *2*
    *232*
      *2*
        *
    
    Reply
  182. Sohail Afridi says

    October 29, 2018 at 8:12 pm

    How Can I Make This Patteran In Singal loop?

                      0
                    101
                  21012
                3210123
              432101234
            54321012345
    
    Reply
    • Akshay Agrawal says

      March 14, 2019 at 5:52 pm

      n=int(input("enter no."))
      for i in range(0,n+1):
          for j in range(i,0,-1):
              print(j,end="")
          print(0,end="")
          for k in range(1,i+1):
              print(k,end="")
          print()
      
      enter no.5
      0
      101
      21012
      3210123
      432101234
      54321012345
      
      Reply
      • Tawa Dandahwa says

        March 16, 2020 at 1:18 am

        Guys help in printing this pattern.

        1****
        12***
        123**
        1234*
        12345
        
        Reply
        • Nar Hari Gautam says

          August 3, 2020 at 8:45 pm

          for i in range(5):
              for j in range(i+1):
                  print((j+1),end="")
              for j in range(5-i-1):
                  print("*",end="")
              print()
          
          		
          Reply
      • Shiwangi Garg says

        December 17, 2020 at 5:08 pm

        A
        B A B
        C B A B C
        D C B A B C D
        A B C B A
        A B A
        A
        Reply
  183. hk6 says

    October 25, 2018 at 7:14 pm

    how can I print this?

    1 2 3 4 5 6
       2 3 4 5 6
          3 4 5 6
             4 5 6
                5 6
                   6
    
    Reply
    • Swarup Sarkar says

      November 16, 2018 at 1:23 pm

      last_num = 7
      for i in range (1, last_num):
       for j in range(i, last_num, +1):
         print( j, end= " ")
       print()
      
      Reply
      • Swarup Sarkar says

        November 16, 2018 at 1:25 pm

        end =” ”
        Sorry for wrong typing

        Reply
    • Yaswanth Reddy says

      February 19, 2019 at 8:05 am

      1 3 5 7 9
      3 5 7 9
      5 7 9
      7 9
      9
      

      slove this

      Reply
      • Akshay Agrawal says

        March 14, 2019 at 6:04 pm

        n=int(input("enter no."))
        for i in range(1,n+1,2):
            for j in range(i,n+1,2):
                print(j,end=" ")
            print()
        
        enter no.9
        1 3 5 7 9 
        3 5 7 9 
        5 7 9 
        7 9 
        9
        
        Reply
      • Devendra says

        November 4, 2022 at 6:43 pm

        How can i get this pattern:

        123456
        78912
        3456
        789
        12
        3

        Reply
    • Akshay Agrawal says

      March 16, 2019 at 12:34 am

      for i in range(1,7):
      	for j in range(i,7):
      		print(j,end="")
      	print()
      
      	
      123456
      23456
      3456
      456
      56
      6
      
      Reply
    • Nar Hari Gautam says

      August 3, 2020 at 9:30 pm

      for i in range(6):
          print(" "*i,end="")
          for j in range(7-i-1):
              print((j+i+1),end="")
            
          print()
      Reply
  184. Rick says

    October 16, 2018 at 10:04 pm

    For this pattern:

    1
    3 2
    4 5 6
    10 9 8 7
    
    Reply
    • Vishal says

      October 18, 2018 at 3:34 pm

      Hey Rick. The solution is added. Please check example 7

      Reply
  185. sss says

    October 13, 2018 at 8:18 pm

    I want python program for this pattern, please

                             1
                        2   3   4
                   5   6  7    8   9
    
    Reply
    • Vishal says

      October 14, 2018 at 11:13 am

      Thank you for your question. I have updated the article. Please check number pattern example 6

      Reply
    • Akshay Agrawal says

      March 12, 2019 at 2:31 pm

      x = int(input("enter no. of rows"))    
      n=1
      for i in range(1,x*2,2):
          for j in range(0,i):
              print(n,"",end="")
              n=n+1
          print()
      
      enter no. of rows3
      1 
      2 3 4 
      5 6 7 8 9
      
      Reply
  186. michael darby says

    October 6, 2018 at 8:14 am

    How do I make an hourglass shape with stars

     *******
        ***** 
         ***
           *
         ***
       *****
     *******
    *********
    
    Reply
    • Pankaj says

      November 9, 2018 at 3:21 pm

      s1 = 0
      e1 = 7
      s2 = 0
      e2 = 0
      for x in range(4):
          for y in range(s2,e2):
              print(" ",end="")
          for z in range(s1,e1):
              print("*",end="")
          print()
          s1 += 1
          e1 -= 1
          e2 += 1
      
      s1 -= 1
      e1 += 1
      e2 -= 1
      
      for x in range(3):
      
          s1 -= 1
          e1 += 1
          e2 -= 1
      
          for y in range(s2,e2):
              print(" ",end="")
          for z in range(s1,e1):
              print("*",end="")
          print()
      
      Reply
    • vishal gaddam says

      December 16, 2018 at 10:50 pm

      for i in range(10,0,-1):
      	if i % 2 !=0:
      		print(i * "*")
      for i in range(2,10):
      	if i % 2 !=0:
      		print(i * "*")
      
      Reply
    • hemant says

      January 23, 2019 at 12:02 pm

      # star Program 
      def first(n):
      		for i in range(0, n):		
      			for j in range(i,n ):
      				print('* ',end='') 
      
      			print("\r")		
      
      		for i in range(0, n):		
      			for j in range(0, i+1):
      				print('* ',end='') 
      
      			print("\r")		
      
      
      inp = input('Enter The Numbers Of Rows ')
      inp = int(inp) 
      first(inp)
      
      Reply
    • Akshay Agrawal says

      March 12, 2019 at 12:07 am

      n=int(input("enter a number : "))
      for i in range(n,0,-1):
          print("*"*i)
      for j in range(1,n+1):
          print("*"*j)
      
      enter a number : 9
      *********
      ********
      *******
      ******
      *****
      ****
      ***
      **
      *
      *
      **
      ***
      ****
      *****
      ******
      *******
      ********
      *********
      
      Reply
    • Akshay Agrawal says

      March 14, 2019 at 11:26 pm

      n=int(input("enter number : "))
      for i in range(n,0,-1):
          print("*"*i)
      for j in range(1,n+1):
          print("*"*j)
      
      enter number : 9
      *********
      ********
      *******
      ******
      *****
      ****
      ***
      **
      *
      *
      **
      ***
      ****
      *****
      ******
      *******
      ********
      *********
      
      Reply
    • Akshay Agrawal says

      March 16, 2019 at 12:38 am

      previews commented wrong code by mistake

      n=int(input("enter a number : "))
      for i in range(n,0,-2):
          print("*"*i)
      for j in range(2,n+1,2):
          print("*"*j)
      
      *********
      *******
      *****
      ***
      *
      **
      ****
      ******
      ********
      
      Reply
  187. Christopher Knox says

    September 27, 2018 at 7:31 am

    How do you make this with a with a while loop?

    *
    **
    ***
    ****
    *****
    ******
    *****
    ****
    ***
    **
    *
    
    Reply
    • Nat says

      September 27, 2018 at 8:12 pm

      num=int(input('Enter a number: '))
      
      while num<=0:
          print('Error! Enter a positive number: ')
          num=int(input('Enter a number: '))
      for row in range (num):
          for col in range (row):
              print('*', end='')
          print()
      for i in range (num,0,-1):
          for j in range (i):
              print('*', end='')
          print()
      
      Reply
      • Neha says

        October 25, 2018 at 10:17 pm

        How can we do this

        1
        12
        123
        12
        1
        
        Reply
        • Akshay Agrawal says

          March 11, 2019 at 9:21 pm

          n = int(input("enter a num"))
          for i in range(1,n):
              for j in range(1,i+1):
                  print(j,end="")
              print()
          for i in range(n,0,-1):
              for j in range(1,i+1):
                  print(j,end="")
              print()
          
          enter a num3
          1
          12
          123
          12
          1
          
          Reply
    • Akshay Agrawal says

      March 11, 2019 at 8:55 pm

      n = int(input("enter a num"))
      i=1
      while i<=n :
          print("* "*i)
          i+=1
      j=1
      while j<=n :
          print("* "*(n-j))
          j+=1
      
      * 
      * * 
      * * * 
      * * * * 
      * * * * * 
      * * * * * * 
      * * * * * * * 
      * * * * * * 
      * * * * * 
      * * * * 
      * * * 
      * * 
      *
      
      Reply
    • Sairam Prudhvi says

      July 26, 2019 at 5:25 pm

      n = int(input())
      k = 0
      for i in range(n,0,-1):
          k += 1 
          for j in range(i,0,-1):
              if j <= k:
                  print('#',end = '')
          print(' ')
      
      Reply
    • sandeep says

      August 25, 2019 at 12:53 pm

      for i in range(1,6):
          for j in range(1,i+1):
              print("*",end=" ")
          print("")
      
      for x in range(5,1,-1):
          for y in range(1,x):
              print("*", end =" ")
          print("")
      
      Reply
  188. Christopher Knox says

    September 27, 2018 at 7:29 am

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

    How do we make this one?

    Reply
    • Natalie says

      October 22, 2018 at 11:41 am

      Is it possible for you to create a Python program for this pattern, please?

      AAAA****AAAA
      BBB***BBB
      CC**CC
      D*D
      
      Reply
      • Pulkit Thakur says

        October 31, 2018 at 4:00 pm

        for i in range(4):
            for j in range(4-i):
                print(chr(65+i),end='')
            for j in range(4-i):
                print("*",end='')
            for j in range(4-i):
                print(chr(65+i),end='')
            print('\n',end='')
        
        Reply
      • vishal gaddam says

        December 16, 2018 at 10:42 pm

        counter = 4
        char = [" ","D","C","B","A"]
        while counter !=0:
        	out1 = char[counter] * counter
        	out2 = "*" * counter
        	print(out1 + out2 + out1)
        	counter -=1
        
        Reply
      • Akshay Agrawal says

        March 11, 2019 at 10:46 pm

        n=5
        for i in range(0,n):
            print(chr(65+i)*(n-i), end="")
            print("*"*(n-i), end="")
            print(chr(65+i)*(n-i), end="")
            print()
        
        AAAA****AAAA
        BBB***BBB
        CC**CC
        D*D
        
        Reply
    • vishal gaddam says

      December 16, 2018 at 9:15 pm

      star = '*'
      counter = 1
      out = 0
      print("Pattern1")
      while counter < 6:
      	out = counter * star
      	print(out)
      	counter +=1
      counter = 5
      while counter !=0:
      	out = counter * star
      	print(out)
      	counter -=1
      
      Reply
      • vishal gaddam says

        December 16, 2018 at 10:07 pm

        write counter = 4 insted of counter=5

        Reply
    • himanshu tiwari says

      March 7, 2019 at 10:17 pm

      n=int(input("enter the number"))
      for i in range(1,n+1):
          s= '*'*i
          print(s)
      for j in range(n+1,1,-1):
          y = '*' * j
          print(y)
      
      Reply
    • Akshay Agrawal says

      March 11, 2019 at 9:25 pm

      n = int(input("enter a num"))
      i=1
      while i<=n :
          print("*"*i)
          i+=1
      j=1
      while j<=n :
          print("*"*(n-j))
          j+=1
      
      enter a num6
      *
      **
      ***
      ****
      *****
      ******
      *****
      ****
      ***
      **
      *
      
      Reply
    • Soumya says

      June 6, 2019 at 7:07 pm

      First by the simple code i in0,6 and j in 0,i and then reverse i in 6,0,-1 and again j in 0,i

      Reply
  189. venom says

    September 24, 2018 at 10:39 pm

    0
    2 2
    4 4 4
    8 8 8 8
    

    how do we make this one?

    Reply
    • EyalMozhi says

      December 4, 2018 at 6:15 pm

      n=int(input("Enter the number:"))
      z=0
      for x in range(0,n):
          for y in range(0,x+1):
              print(z,end='')
          z=2**(x+1)
          print()
      
      Reply
      • Rohan says

        January 14, 2019 at 2:29 pm

        https://paste.pound-python.org/show/ABB0xOHlvRVauIaa6lpV/

        Please help me with this.

        Reply
    • Akshay Agrawal says

      March 16, 2019 at 11:23 pm

      e=int(input("Enter the number:"))
      n=0
      for i in range(1,e+1):
          for j in range(0,i):
              print(n,end=" ")
          n=2**i
          print()
      
      Enter the number:4
      0 
      2 2 
      4 4 4 
      8 8 8 8
      
      Reply
  190. Sankar says

    September 24, 2018 at 8:17 pm

    1
    2   6
    3   7  10
    4   8   11  13 
    5   9    12  14   15
    

    I want this pattern in python

    Reply
    • Akshay Agrawal says

      March 16, 2019 at 11:20 pm

      num=int(input("enter no. of rows : "))
      for i in range(num):
          val=i+1
          for j in range(i+1):
              print(format(val, "<4"), end="")
              val=val+((num-1)-j)
          print()
      
      enter no. of rows : 5
      1   
      2   6   
      3   7   10  
      4   8   11  13  
      5   9   12  14  15
      
      Reply
    • guha says

      May 24, 2019 at 6:08 pm

      print("1
      2 6
      3 7 10
      4 8 11 13
      5 9 12 14 15");
      
      Reply
    • Kaif says

      June 6, 2019 at 3:01 pm

      For i in range(1,6):
      K=i
      M=4
      For j in range(i):
      Print(k,end=' ')
      K=K+M
      M=M-1
      Print ()
      
      Reply
    • Naina says

      December 12, 2022 at 6:49 pm

      d=4
      f=0
      for i in range(1,n+1):
      print(i,end=" ")
      f=i+d
      for j in range(1,i):
      print(f,end=" ")
      d-=1
      f += d
      print()
      d=4

      Reply
    • Gaurav says

      December 12, 2022 at 6:50 pm

      d=4
      f=0
      for i in range(1,n+1):
      print(i,end=" ")
      f=i+d
      for j in range(1,i):
      print(f,end=" ")
      d-=1
      f += d
      print()
      d=4

      Reply
  191. Blaize says

    September 18, 2018 at 2:01 pm

                
                 1
              1  2
          1  2  3
       1 2  3  4
    1 2 3  4  5
    

    Print the above pattern in python.

    Reply
    • S.PAWANA says

      September 19, 2018 at 11:24 pm

      for i in range(1,6):
            for j in range(1,i+1):
                      print(j,end=' ')
           print( )
      
      Reply
      • Vishal says

        September 21, 2018 at 4:21 pm

        Right

        Reply
    • Vishal says

      September 21, 2018 at 4:22 pm

      Hey Blaize.
      I have updated the post with your question. Please check

      Reply
      • Rohan says

        January 14, 2019 at 1:07 pm

        How to print this pattern in python?

        
          ---------.|.---------
             ------.|..|..|.------
               ---.|..|..|..|..|.---
        -------WELCOME-------
               ---.|..|..|..|..|.---
             ------.|..|..|.------
           ---------.|.---------
        
        Reply
        • Vishal says

          January 14, 2019 at 3:03 pm

          Will check and let you know

          Reply
          • Dipanshu upadhyay says

            August 24, 2020 at 9:15 pm

            1 
            1 3
            1 3 5
            1 3 5 7
            1 3 5 7 11
            1 3 5 7 11
        • Ratan says

          May 17, 2019 at 3:08 pm

          N, M = map(int,input("Enter input: ").split())
          for i in range(1,N,2):
              print((i * ".|.").center(M, "-"))
          print("WELCOME".center(M,"-"))
          for i in range(N-2,-1,-2):
              print((i * ".|.").center(M, "-"))
          
          Reply
        • Jspawa says

          September 30, 2020 at 7:41 pm

          Print(' ---------.|.---------
               ------.|..|..|.------
                 ---.|..|..|..|..|.---
          -------WELCOME-------
                 ---.|..|..|..|..|.---
               ------.|..|..|.------
             ---------.|.---------')
          Reply
    • mahesh says

      October 6, 2018 at 5:51 pm

      How to print “M” in star(*)

      Reply
      • Vishal says

        October 6, 2018 at 6:45 pm

        Hey Mahesh

        print("m ", end=' ')
        

        instead of

        print("* ", end=' ')
        
        Reply
    • Prathap says

      November 2, 2018 at 5:37 pm

      N=5
      for I in range(1,n+1):
      K=1
      for j in range(1,n+1):
      If i>=j:
      Print(k,end=' ')
      Else:
      Print(' ',end=' ' )
      Print()
      
      Reply
    • Rathnam Koninti says

      January 9, 2019 at 6:30 pm

      num=6
      for row in range(1, num):
          for column in range(1, row + 1):
              print(column, end=' ')
          print("")
      
      Reply
    • hemant says

      January 23, 2019 at 12:06 pm

      # star Program 
      def first(n):
      		
      
      		for i in range(0, n):		
      			for j in range(0, i+1):
      				print(j+1,end='') 
      
      			print("\r")		
      
      
      inp = input('Enter The Numbers Of Rows ')
      inp = int(inp) 
      first(inp)
      
      Reply
    • amit says

      February 20, 2019 at 8:45 pm

      lastNumber = 6
      for i in range(1 , lastNumber):
          for j in range(1 , i+1):
              print(j , end="")
          print(" ")
      
      Reply
    • shivdas says

      March 3, 2019 at 9:19 pm

      print("Second Number Pattern ")
      lastNumber = 6
      for row in range(1, lastNumber):
          for column in range(1, row + 1):
              print(column, end=' ')
          print("")
      
      Reply
    • Shivam Srivastava says

      May 7, 2019 at 4:40 pm

      for i in range(1,n+1):
          for j in range(1,i+1):
              print(j,end="")
          print()
      
      Reply
    • Tariq Khan says

      May 14, 2019 at 7:03 pm

      def pattern(n):
          for i in range(1,n+1):
              for j in range(1,i+1):
                  print(j ,end=' ')
              print()
      n=int(input("How many row you want to enter?"))
      pattern(n)
      
      Reply
    • subham subhasis says

      July 2, 2019 at 7:32 am

      print("Second Number Pattern ")
      lastNumber = 6
      for row in range(1, lastNumber):
          for column in range(1, row + 1):
              print(column, end=' ')
          print("")
      
      Reply
    • Raja Babu says

      August 4, 2019 at 11:11 pm

      row = int(input("Enter size"))
      for row in range(1, row):
          for column in range(1, row + 1):
              print(column, end=' ')
          print("")
      
      Reply
      • Pooja says

        September 28, 2021 at 1:04 pm

        How to print prime numbers in pyramid pattern?

                   2 
                 3 5
             7  11 13
          17 19 23 29
        31 37 41 43 47
        Reply
        • Mohammad ghazi says

          January 5, 2022 at 10:04 am

          x = []
          for h in range(2,50):
              for j in range(2,h):
                  if h%j==0:
                      break
              else:
                  x.append(h)
          
          m = 0
          n = 6
          for i in range(1,n):
              for j in range(i,n):
                  print(' ',end=' ')
              for j in range(i):
                  print(x[m], end=' ')
                  m+=1
              print()
          Reply
    • sandeep says

      August 25, 2019 at 12:50 pm

      for i in range(1,6):
          for j in range(5,i,-1):
              print(" ",end=" ")
          for k in range(1,i+1):
              print(k,end=" ")
          print("")
      
      Reply
      • anshuuu says

        June 16, 2020 at 10:29 am

        1
        24
        135
        2468
        13579
        
        Reply
        • Adina says

          June 11, 2021 at 7:31 pm

          1 3 5 7 9
          1 3 5 7
          1 3 5
          1 3
          1
          Reply
          • Divya Singh says

            December 4, 2021 at 7:35 pm

            n=1 
            m=5
            for i in range(5,0,-1):
                for j in range(0,m):
                    print(n,end='')
                    n+=2
                print('')
                n=1
                m-=1
          • Divya Singh says

            December 4, 2021 at 7:39 pm

            n=1 
            m=5
            for i in range(5,0,-1):
                for j in range(0,m):
                    print(n,end='' ")
                    n+=2
                print('' ")
                n=1
                m-=1
        • Divya Singh says

          December 5, 2021 at 12:21 am

          m=1 
          n=2
          for i in range(1,6):
              for j in range(1,i+1):
                  if i%2!=0:
                      print(m,end=" ")
                      m+=2
              
                  else:
                      print(n,end=" ")
                      n+=2
                      
              n=2
              m=1 
              print(" ")
          Reply
          • Himesh c. says

            January 5, 2024 at 11:06 am

            rows = int(input (“enter the number of rows : “))
            for i in range(1, rows + 1):
            for j in range(1, i + 1):
            print(i * j, end=’ ‘)
            print()

Leave a Reply Cancel reply

your email address will NOT be published. all comments are moderated according to our comment policy.

Use <pre> tag for posting code. E.g. <pre> Your entire code </pre>

In: Python Python Basics
TweetF  sharein  shareP  Pin

  Python Tutorials

  • Get Started with Python
  • Python Statements
  • Python Comments
  • Python Keywords
  • Python Variables
  • Python Operators
  • Python Data Types
  • Python Casting
  • Python Control Flow statements
  • Python For Loop
  • Python While Loop
  • Python Break and Continue
  • Python Nested Loops
  • Python Input and Output
  • Python range function
  • Check user input is String or Number
  • Accept List as a input from user
  • Python Numbers
  • Python Lists
  • Python Tuples
  • Python Sets
  • Python Dictionaries
  • Python Functions
  • Python Modules
  • Python isinstance()
  • Python OOP
  • Python Inheritance
  • Python Exceptions
  • Python Exercise for Beginners
  • Python Quiz for Beginners

 Explore Python

  • Python Tutorials
  • Python Exercises
  • Python Quizzes
  • Python Interview Q&A
  • Python Programs

All Python Topics

  • Python Basics
  • Python Exercises
  • Python Quizzes
  • Python File Handling
  • Python Date and Time
  • Python OOP
  • Python Random
  • Python Regex
  • Python Pandas
  • Python Databases
  • Python MySQL
  • Python PostgreSQL
  • Python SQLite
  • Python JSON

About PYnative

PYnative.com is for Python lovers. Here, You can get Tutorials, Exercises, and Quizzes to practice and improve your Python skills.

Follow Us

To get New Python Tutorials, Exercises, and Quizzes

  • Twitter
  • Facebook
  • Sitemap

Explore Python

  • Learn Python
  • Python Basics
  • Python Databases
  • Python Exercises
  • Python Quizzes
  • Online Python Code Editor
  • Python Tricks

Coding Exercises

  • C Exercises
  • C++ Exercises
  • Python Exercises

Legal Stuff

  • About Us
  • Contact Us

We use cookies to improve your experience. While using PYnative, you agree to have read and accepted our:

  • Terms Of Use
  • Privacy Policy
  • Cookie Policy

Copyright © 2018–2026 pynative.com