hacker rank python problem(Alphabet rangoli)
ALPHABET RANGOLI
def print_rangoli(size):
# your code goes here
alpha = ['a']
for i in range(size-1):
alpha.append(chr(ord(alpha[i]) + 1))
poped = []
beta = list(alpha)
beta.reverse()
beta.pop() # remove the extra a => e,c,d,b
full_list = list(beta)
full_list.extend(alpha)
# to determine the width of the line with no outer dashes
max_len = len('-'.join(full_list))
for j in range(1,size+1):
m_str = ""
if (j-1) > 0:
m_str = '-'.join(beta[:j-1]) + '-'
m_str += '-'.join(alpha[j*-1:])
string = '{s:{c}^{n}}'.format(s=m_str, n=max_len, c='-')
poped.append(string)
# upper part
print('\n'.join(poped))
poped.pop()
poped.reverse()
# lower part
print('\n'.join(poped))
Comments