We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
def print_rangoli(size):
length=((size * 2) - 1)
base = [abs(size - x - 1) for x in range(length)]
for i in range(length):
new = [x + base[i] for x in base]
prepend=''
for e in new:
if e > size - 1:
print(prepend+'-', end='')
else:
print(prepend+chr(ord('a')+e), end='')
prepend='-'
print('')
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Alphabet Rangoli
You are viewing a single comment's thread. Return to all comments →
def print_rangoli(size): length=((size * 2) - 1) base = [abs(size - x - 1) for x in range(length)] for i in range(length): new = [x + base[i] for x in base] prepend='' for e in new: if e > size - 1: print(prepend+'-', end='') else: print(prepend+chr(ord('a')+e), end='') prepend='-' print('')