Alphabet Rangoli

Sort by

recency

|

1399 Discussions

|

  • + 0 comments

    from string import ascii_lowercase def print_rangoli(size): patterns= list(reversed(ascii_lowercase[:size])) for i in range(1, size+1): print("-".join(patterns[0:i] + list(reversed(patterns[0:i]))[1:]).center((size*2 -1)*2 -1,"-")) for i in range(size-1,0,-1): print("-".join(patterns[0:i] + \ list(reversed(patterns[0:i]))[1:]).center((size*2 -1)*2 -1,"-"))

    if name == 'main': n = int(input()) print_rangoli(n)

  • + 0 comments

    def print_rangoli(size): # based on (abs(x) + abs(y) < size) against position of 'a' : (size-1, size*2 -2) alpha='abcdefghijklmnopqrstuvwxyz'

    for i in range(size*2 - 1) : 
          print (''.join([alpha[abs(i-size+1) + int(abs(j-size*2+2)/2)] \
                    if abs(j-size*2+2) % 2 ==0 and abs(i-size+1) + abs(j-size*2+2)/2 < size else '-' for j in range(size*4-3)]))
    
  • + 0 comments
    width= 2*(2*(size-1)) + 1
    str=''
    highest_val = 97+size-1
    if(size==1):
        print('a')
    else:
        for row in range(1,2*size):
            if(row <= size): # top triangle + central line
                substr =''
                for h in range(0,row):
                    substr += chr(highest_val-h)+'-'
                rsubstr = substr[::-1] # reverse of the string
                str += (substr + rsubstr[3:]).center(width,'-') +'\n'
            else:
                pass
        bottom_str=str[::-1] # reverse the whole upper triangle string + the middle line str
        str += bottom_str[width+2:] # remove the whole middle line + the newline character
        print(str)
    
  • + 0 comments
    import math
    
    
    def get_char_seq(j, n):
        str1 = ''
        for i in range(1, j + 1):
            str1 += chr(97 + n - i)
        str1 = '-'.join(str1)
        return str1
    
    def get_string(i,size,columns):
            str1 = get_char_seq(i, size)
            str2 = str1[:-2]
            str2 = ''.join(reversed(str2))
            left_dash = ((math.floor(columns / 2) + 1) - len(str1)) * '-'
            right_dash = ((math.floor(columns / 2) - 1) - len(str2)) * '-'
            full_string=left_dash + str1 + '-' + str2 + right_dash
            return full_string
            
    def print_rangoli(size):
        # your code goes here
        columns = 4 * size - 3
        if size==1:
            print('a')
        else:
          for i in range(1, size + 1):
            full_string=get_string(i,size,columns)
            print(full_string)
          for i in range(size - 1, 0, -1):
            full_string=get_string(i,size,columns)
            print(full_string)
    
    
    if __name__ == '__main__':
        n = int(input())
        print_rangoli(n)
    
  • + 0 comments
    size = 3
    alphabets = [chr(i) for i in range(97,97+size)]
    alphabets.reverse()
    # print(alphabets)
    
    a = [alphabets[0]]
    for i in range(1,len(alphabets)+1):
        a.append('-'.join(alphabets[0:i])+'-'+'-'.join(alphabets[0:i+1][::-1]))
    # print("{}".format(a)+"->size = "+"{}".format(len(a)))
    s = 0
    for i in range(size*2-2,0,-2):
        print('-'*i+a[s]+'-'*i)
        s += 1
    print(a[s])
    for _ in range(size-1):
        print('-'*i+a[s-1]+'-'*i)
        i += 2
        s -= 1