Hollow Pattern in Python [closed]

  c++, python

I need to write code to produce the following pattern (with n = 6 shown):

      6
     5 5
    4   4
   3     3
  2       2
 1         1
0 1 2 3 4 5 6

I have tried to do this using this code:

 n = int(input("num: "))
    k = 2
    for row in range(1,n+1):
        for col in range(1,2*n):
            if row+col==n+1 or col-row==n-1:
                print("i", end="")
            elif row ==n and col != k:
                print(col,end="")
                k += 2
            else:
                print(end=" ")
        print()

Source: Windows Questions C++

LEAVE A COMMENT