Dremendo Tag Line

Print pyramid star pattern using for loop in Python

for Loop - Question 18

In this question, we will see how to print the pyramid star pattern in Python programming using for loop. To know more about for loop click on the for loop lesson.

Q18) Write a program in Python to print the pyramid star pattern using for loop.

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

Program

for r in range(1,6):

    # printing the space
    for c in range(4,r-1,-1):
        print(' ',end='')

    # printing the star
    for c in range(0,r):
        print('* ',end='')       # print the star with a space, it will make a triangle

    print()

Output

    *
   * *
  * * *
 * * * *
* * * * *
video-poster