Alphabet Rangoli

  • + 0 comments
        # your code goes here
        a=0
        for i in range(1, n*2):
            mid = (n*4-2)//2
            if i<n:
                k = (n*4-3)-(i*2-1)
                asc=97+(n-1)
                for j in range(1,k+1):
                    if(j>=mid-a and j<=(k+2)/2):
                        print(chr(asc)+"-", end="")
                        temp = asc
                        asc -= 1
                    elif(j>(k+2)/2 and j<=mid):
                        temp += 1
                        print(chr(temp)+"-", end="")
                    else:
                        print("-", end="")
                a += 2
                print()
            elif i==n:
                asc = 97+(n-1)
                for j in range(1,(n*4-2)):
                    if j<=mid:
                        if j%2==0:
                            print("-", end="")
                        else:
                            print(chr(asc), end="")
                            temp=asc
                            asc -= 1
                    else:
                        if j%2==0:
                            print("-", end="")
                        else:
                            temp += 1
                            print(chr(temp), end="")
                print()
            else:
                a -= 2
                asc=97+(n-1)
                k2 = (i*2)-2
                for j in range(1,k2+1):
                    if(j>=mid-a and j<=(k2+2)/2):
                        print(chr(asc)+"-", end="")
                        temp = asc
                        asc -= 1
                    elif(j>(k2+2)/2 and j<=mid):
                        temp += 1
                        print(chr(temp)+"-", end="")
                    else:
                        print("-", end="")
                print()
    
    if __name__ == '__main__':
        n = int(input())
        print_rangoli(n)