Alphabet Rangoli

Sort by

recency

|

1348 Discussions

|

  • + 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,"-"))
    
  • + 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))
    
  • + 0 comments

    It’s a great exercise in loops and string manipulation, and the final result is rewarding! Betbook 250.com Login

  • + 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)
    
  • + 0 comments
        ord_a = 97
        lines = []
        ord_last_char = size + ord_a - 1
        for num_chars in range(1, size + 1):
            left_str_list = [chr(ord_char) for ord_char in range(ord_last_char, ord_last_char - num_chars, -1)]
            string = '-'.join(left_str_list + left_str_list[-2::-1])
            line = string.center(4 * size - 3, '-')
            lines.append(line)
            print(line)
    
        for idx in range(len(lines) - 2, -1, -1):
            print(lines[idx])