-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAlphabet_Rangoli.py
112 lines (89 loc) · 2.79 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# You are given an integer, . Your task is to print an alphabet rangoli of size . (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 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 , the size of the rangoli.
# Constraints
# Sample Input
# 5
# Sample Output
# --------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--------
def print_rangoli(size):
# your code goes here
width = size*4-3
string = ''
for i in range(1,size+1):
for j in range(0,i):
string += chr(96+size-j)
if len(string) < width :
string += '-'
for k in range(i-1,0,-1):
string += chr(97+size-k)
if len(string) < width :
string += '-'
print(string.center(width,'-'))
string = ''
for i in range(size-1,0,-1):
string = ''
for j in range(0,i):
string += chr(96+size-j)
if len(string) < width :
string += '-'
for k in range(i-1,0,-1):
string += chr(97+size-k)
if len(string) < width :
string += '-'
print(string.center(width,'-'))
if __name__ == '__main__':
n = int(input())
print_rangoli(n)