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.
# your code goes here
z = "abcdefghijklmnopqrstuvwxyz"
#join till nth string
b = "".join(z[:n])
#reverse it 1st half
b = b[::-1]
#c holds
# (i)loop for i till n
# (ii)all items of b till i
# (iii)all items including i and reversed
c = [b[:i]+b[:i+1][::-1] for i in range(n)]
# from list c it joins all the items with dash
# also it centers the item with n*4-3 width and - for spaces
d=["-".join(i).center(n*4-3,"-") for i in c]
#top half
#prints the items of d after a new line
print("\n".join(d))
#bottom half
#prints the items of d in reverse after new line
#the middle line is ignored ... [1:]
print("\n".join(d[::-1][1:]))
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 →
entre vouz
def print_rangoli(n):
if name == 'main': n = int(input()) print_rangoli(n)