Python Program

How to print patter A in python    
#code
for i in range (1,7):
    for j in range (1,7):
        if i==1 and j in {2,3,4,5}:
            print("*",end=' ')
        elif i in {2,3,4,5} and j in {1,6}:
            print("*",end=' ')
        elif i==3:
            print("*",end=' ')
        else:
            print(" ",end=' ')
    print()

#code:2
for i in range(1,6):
    for j in range(1,7):
        if i==1 and j in {2,3,4,5} or i in {2,3,4,5} and j in {1,6} or i==3:
            print("*",end='')            
        else:
            print(" ",end='')
    print()
        
explanation:

for i in range (1,7):
    for j in range (1,7):
        if i==1 and j in {2,3,4,5}:
            print("*",end=' ')

here it means after defining the range of rows an column ,
we are going to print first row of stars.
if i==1 and j in {2,3,4,5}:
using this code.

after printing first line......
elif i in {2,3,4,5} and j in {1,6}:
            print("*",end=' ')
        elif i==3:
            print("*",end=' ')
 after this we have to print the leg of A. so 

elif i in {2,3,4,5} and j in {1,6}:
            print("*",end=' ')
after it we required the middle line of A so

        elif i==3:
            print("*",end=' ')
using this code we draw the middle line of A
Afer this we have to required  
to print space such that it will appear as a right alphabet

else:
    print(" ",end='')

now to change row we required:
print()

Thankyou
    
        .

Post a Comment

Previous Post Next Post