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.
This here seems to be much easier with simple mirroring technique
def print_rangoli(size):
alpha = "abcdefghijklmnopqrstuvwxyz"
width = size *4 -3
for i in range(size-1, -1, -1):
left = alpha[size-1: i : -1]
mid = alpha[i]
right = alpha[i+1 :size ]
final = '-'.join(left + mid + right)
final1 = final.center(width, '-')
print(final1)
for i in range(1,size):
mid = alpha[i]
left = alpha[size-1: i : -1]
right = alpha[i+1 :size ]
final = '-'.join(left + mid + right)
final1 = final.center(width, '-')
print(final1)
if name == 'main':
n = int(input())
print_rangoli(n)
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 →
This here seems to be much easier with simple mirroring technique
def print_rangoli(size): alpha = "abcdefghijklmnopqrstuvwxyz" width = size *4 -3 for i in range(size-1, -1, -1): left = alpha[size-1: i : -1] mid = alpha[i] right = alpha[i+1 :size ]
if name == 'main': n = int(input()) print_rangoli(n)