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.
- Prepare
- Python
- Strings
- Alphabet Rangoli
- Discussions
Alphabet Rangoli
Alphabet Rangoli
Sort by
recency
|
1399 Discussions
|
Please Login in order to post a comment
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)
def print_rangoli(size): # based on (abs(x) + abs(y) < size) against position of 'a' : (size-1, size*2 -2) alpha='abcdefghijklmnopqrstuvwxyz'