-
Notifications
You must be signed in to change notification settings - Fork 0
/
alphabet_rangoli.py
79 lines (70 loc) · 2.24 KB
/
alphabet_rangoli.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# You are given an integer, N. Your task is to print an alphabet rangoli of size N. (Rangoli is a form of Indian folk art based on creation of patterns.)
# Different sizes of alphabet rangoli are shown below:
# #size 3
# ----c----
# --c-b-c--
# c-b-a-b-c
# --c-b-c--
# ----c----
# #size 5
# --------e--------
# ------e-d-e------
# ----e-d-c-d-e----
# --e-d-c-b-c-d-e--
# e-d-c-b-a-b-c-d-e
# --e-d-c-b-c-d-e--
# ----e-d-c-d-e----
# ------e-d-e------
# --------e--------
# #size 10
# ------------------j------------------
# ----------------j-i-j----------------
# --------------j-i-h-i-j--------------
# ------------j-i-h-g-h-i-j------------
# ----------j-i-h-g-f-g-h-i-j----------
# --------j-i-h-g-f-e-f-g-h-i-j--------
# ------j-i-h-g-f-e-d-e-f-g-h-i-j------
# ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
# --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
# j-i-h-g-f-e-d-c-b-a-b-c-d-e-f-g-h-i-j
# --j-i-h-g-f-e-d-c-b-c-d-e-f-g-h-i-j--
# ----j-i-h-g-f-e-d-c-d-e-f-g-h-i-j----
# ------j-i-h-g-f-e-d-e-f-g-h-i-j------
# --------j-i-h-g-f-e-f-g-h-i-j--------
# ----------j-i-h-g-f-g-h-i-j----------
# ------------j-i-h-g-h-i-j------------
# --------------j-i-h-i-j--------------
# ----------------j-i-j----------------
# ------------------j------------------
# The center of the rangoli has the first alphabet letter a, and the boundary has the Nth alphabet letter (in alphabetical order).
# Function Description
# Complete the rangoli function in the editor below.
# rangoli has the following parameters:
# int size: the size of the rangoli
# Returns
# string: a single string made up of each of the lines of the rangoli separated by a newline character (\n)
# Input Format
# Only one line of input containing size, the size of the rangoli.
def print_rangoli(s):
# your code goes here
ab='abcdefghijklmnopqrstuvwxyz'
mid=((n+(n-1))*2)-1
rev=[]
for i in range(s):
r=''
k=''
for j in range(i+1):
if j==i:
r+=ab[s-1-j]
top=r+k[::-1]
t=top.center(mid,"-")
rev.append(t)
print(t)
else:
r+=ab[s-1-j]+"-"
k=r
for i in range(s-1):
print(rev[s-2-i])
if __name__ == '__main__':
n = int(input())
print_rangoli(n)