CBSE 11TH CLASS CS PROGRAM 4

 

4. Generate the following patterns using nested loops.

Python

rows = 5

 

for i in range(1, rows + 1):

    for j in range(1, i + 1):

        print("*", end="")

    print()

 

for i in range(rows, 0, -1):

    for j in range(1, i + 1):

        print("*", end="")

    print()

No comments:

Post a Comment