DEV Community

Navnit Rai
Navnit Rai

Posted on

Webkul pattern question advance pattern for interview with python

n=5
for i in range(n-2):
    for j in range(i+1):
        print("*",end='')
    print()
print("*"*(n-1),end='')
print(" "*(n+1),end='')
print("*")
print("*"*(2*n+2))
print("*"*(n-1),end='')
print(" "*(n+1),end='')
print("*")

for i in range(n):
    for j in range(n-i-2):
        print("*",end='')
    print()                                

Enter fullscreen mode Exit fullscreen mode


# n=3
# *
# **    *
# ********
# **    *
# *

# n=5

# *             
# **           
# ***         
# ****      *
# ************
# ****      *
# ***
# ***
# **
# *       

Enter fullscreen mode Exit fullscreen mode
# #webkul pattern program round 1 
# #pattern runs for odd number like min 3 , 5, 7 etc
# #here is ther pattern
# #for n==3
# *       *
# **     **
# ***@@@***
#    @@@
#    @@@
#    ***
#     *
# #for n==5 
# *             *
# **           **
# ***         ***
# ****       ****
# *****@@@@@*****
#      @@@@@
#      @@@@@
#      @@@@@
#      @@@@@
#      *****
#       ***
#        *
# #and so on for n==7.....
# #here is the program


n=5
for i in range(n+1):
    for j in range(i):
        print('*',end='')
    for j in range(n-i):
        print(' ',end='')
    for j in range(n):
        if(i==n):
            print('@',end='')
        else:
            print(' ',end='')
    for j in range(n-i):
        print(' ',end='')
    for j in range(i):
        print('*',end='')
    print()
for i in range(n-1):5
    for j in range(3*n):
        if(j<n or j>2*n-1):
            print(' ',end='')
        else:
            print('@',end='')
    print()
for i in range(n//2+1):
    for j in range(n):
        print(' ',end='')
    for j in range(i):
        print(' ',end='')
    for j in range(n-2*i):
        print('*',end='')
    for j in range(i):
        print(' ',end='')
    for j in range(n):
        print(' ',end='')
    print()

Enter fullscreen mode Exit fullscreen mode
# Input : 3
# Output : 
#                             @
#                            @@@
#                           @@@@@
#                           *   *
#                          **@@@**
#                           *   *
# Input : 5
# Output : 
#                             @
#                            @@@
#                           @@@@@
#                          @@@@@@@
#                          *     *
#                         **     **
#                        ***@@@@@***
#                         **     **
#                          *     *


Enter fullscreen mode Exit fullscreen mode
n=3
for i in range(n//2+2):
    for j in  range(n-i):
        print(" ",end='')
    for j in range(1+2*i):
        print('@',end='')
    print()
for i in range(1,n//2+1):
    if(i<n//2+1):
        for j in range(n//2-i+1):
            print(' ',end='')
        for j in range(i):
            print("*",end="")
        for j in range(n):
            print(" ",end='')
        for j in range(i):
            print("*",end="")
    print()
for i in range(1):
    for j in range(n+2*(n//2+1)):
        if(j<n//2+1 or j>n+n//2):
            print("*",end='')
        else:
            print('@',end='')
    print()
for i in range(n//2):
    for j in range(i+1):
        print(' ',end='')
    for j in range(n//2-i):
        print('*',end='')
    for j in range(n):
        print(' ',end='')
    for j in range(n//2-i):
        print('*',end='')
    print()
Enter fullscreen mode Exit fullscreen mode

# n=3

# @       
# @@      @@@
# @@@*****@@@
# @@      @@@
# @       


# n=5

# @          
# @@         @@@@@
# @@@        @@@@@
# @@@@*******@@@@@
# @@@        @@@@@
# @@         @@@@@
# @     


n=5
for i in range(n-1):
    for j in range(i+1):
        print('@',end='')
    for j in range(n-2-i):
        print('_',end='')
    for j in range(n+2):
        if(i==n-2):
            print('*',end='')
        else:
            print('_',end='')
    for j in range(n):
        if(i>0):
            print('@',end='')
        else:
            print('_',end='')
    print()

for i in range(n//2+1):
    for j in range(n//2+1-i):
        print('@',end='')
    for j in range(i):
        print('_',end='')
    for j in range(n+3):
        print('_',end='')
    for j in range (n):
        if(i<n//2):
            print('@',end='')
        else:
            print(' ',end='')
    print()
Enter fullscreen mode Exit fullscreen mode
# n=3
#     *
#   ***
#   @ @   
# ***@ @***
#  *     *


# n=5
#       *
#       ***
#      *****
#      @   @     
#      @   @     
#      @   @     
# *****@   @*****
#  ***       ***
#   *         *



n=5
for i in range(n//2+1):
    for j in range(n):
        print(' ',end='')
    for j in range(n//2-i):
        print(' ',end='')
    for j in range(1+2*i):
        print('*',end='')
    print()
for i in range(n-1):
    for j in range(3*n):
        if(j==n or j==2*n-1):
            print('@',end='')
        elif(i==n-2 and(j<n or j>2*n-1)):
            print('*',end='')
        else:
            print(' ',end='')
    print()
for i in range(n//2):
    for j in range(i+1):
        print(' ',end='')
    for j in range(n-2-2*i):
        print('*',end='')
    for j in range(i+1):
        print(' ',end='')
    for j in range(n):
        print(' ',end='')
    for j in range(i+1):
        print(' ',end='')
    for j in range(n-2-2*i):
        print('*',end='')
    print()



Enter fullscreen mode Exit fullscreen mode
n= int(input("enter only odd number"))


for i in range(n//2+1):
    for j in range(n//2):
        print("-",end="")
    for j in range(i):
        print("1",end="")
    for j in range(n-2*i):
        print("@",end="")
    print()

for i in range(n):
    for j in range(n):
        if i==0 or j==n-1 or j==0:
            print("*",end="")
        else:
            print("-",end="")



    print()```


Enter fullscreen mode Exit fullscreen mode

Top comments (0)