Tuesday, 6 February 2024

Class 11 CS Practical - 16

 

16 - Write a program in Python to generate the following pattern using nested loops:

     1

   123

  12345

 1234567

123456789


sp=5

k=2

for i in range(1,6):

    for s in range(1,sp):

        print(end=' ')

    for j in range(1,k):

        print(j,end='')

    print()

    sp=sp-1

    k=k+2


 Output:

     1

   123

  12345

 1234567

123456789

No comments:

Post a Comment