Robotics & Artificial Intelligence

Write a python program to print a pyramid using 'for' loop.

Python Control Flow

2 Likes

Answer

rows = 5

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

Output

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

Answered By

2 Likes


Related Questions