Alphabet Rangoli

  • + 0 comments

    Really enjoyed solving it! Great to see so many different solutions here but sad at the same time im unable to understand most rn.. 😅

    def print_rangoli(size):
        alphabets = [chr(i) for i in range(97,97+size)]
        width = size + (size-1)*3
        lines = []
        for i in range(0,size):
            line = str(alphabets[i])
            for j in range(i+1,len(alphabets)):
                line = alphabets[j] + "-" + line
                line += "-" + alphabets[j]   
            lines.insert(0,line.center(width,"-"))
            if i != 0:
                lines.append(line.center(width,"-"))
            
        for i in lines:
            print(i,end="\n")