Alphabet Rangoli

  • + 0 comments
    def build_line(size, idx):
        line = ""
        spacer_len = ((size - (idx+1)) * 2)
        line += "-" * spacer_len
        letters = []
        for j in range(idx + 1):
            letters += ALPHABET[(size-1)-j]
        for k in range(idx - 1, -1, -1):
            letters += ALPHABET[(size-1)-k]
        line += "-".join(letters)
        line += "-" * spacer_len
        return line
    
    def print_rangoli(size):
        for i in range(size):
            print(build_line(size, i))
        for i in range(size - 2, -1, -1):
            print(build_line(size, i))