Tuesday, 6 February 2024

Class 11 CS Practical - 17

 

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

ABCDEFEDCBA

ABCDE EDCBA

ABCD      DCBA

ABC            CBA

AB                 BA

A                       A


y=71

sp=2

for i in range(1,8):

    x=65

   

    while(x<y):

        print(chr(x),end='')

        x=x+1

    if i==1:

        x=x-2

    else:

        x=x-1

        for s in range(1,sp):

            print(end=' ')

        sp=sp+2   

    while(x>64):

        print(chr(x),end='')

        x=x-1

    print()

    y=y-1

   

Output:

ABCDEFEDCBA

ABCDE EDCBA

ABCD      DCBA

ABC            CBA

AB                 BA

A                       A


No comments:

Post a Comment