Alphabet Rangoli

  • + 0 comments
    def print_rangoli(number):
        total_rows = []
        for i in range(1,(number+1)):
            row_length = i
            descending_part = [chr(96 + number - j) for j in range(row_length)]
            rows = descending_part + descending_part[-2::-1]
            total_rows.append("-".join(rows))
        max_width = len(total_rows[-1])
        for k in total_rows:
            print(k.center(max_width,"-"))
        for k in reversed(total_rows[:-1]):
            print(k.center(max_width,"-"))