Alphabet Rangoli

  • + 0 comments

    entre vouz

    def print_rangoli(n):

    # your code goes here
    z = "abcdefghijklmnopqrstuvwxyz"
    #join till nth string
    b = "".join(z[:n])
    #reverse it 1st half 
    b = b[::-1]
    #c holds
    # (i)loop for i till n
    # (ii)all items of b till i
    # (iii)all items including i and reversed
    c = [b[:i]+b[:i+1][::-1] for i in range(n)]
    # from list c it joins all the items with dash
    # also it centers the item with n*4-3 width and - for spaces 
    d=["-".join(i).center(n*4-3,"-") for i in c]
    #top half
    #prints the items of d after a new line
    print("\n".join(d))
    #bottom half
    #prints the items of d in reverse after new line
    #the middle line is ignored ... [1:]
    print("\n".join(d[::-1][1:]))
    

    if name == 'main': n = int(input()) print_rangoli(n)