-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalphabet_rangoli.py
45 lines (36 loc) · 1.29 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
def print_rangoli(size):
# Mid and upper part of the shape.
for i in range(size):
start_char = 96 + size - i
line = ["-"] * (size * 4 - 3)
# Mid until left extreme of the line.
pos = len(line) // 2
# Start printing few characters and increase.
for j in range(start_char, start_char + i + 1, 1):
line[pos] = chr(j)
pos -= 2
# Next of mid until right extreme of the line.
pos = len(line) // 2 + 2
for j in range(start_char + 1, start_char + i + 1, 1):
line[pos] = chr(j)
pos += 2
print("".join(line))
# Lower part of the shape.
for i in range(1, size):
start_char = 97 + i
line = ["-"] * (size * 4 - 3)
# Mid until left extreme of the line.
pos = len(line) // 2
# Start printing many characters and decrease.
for j in range(start_char, start_char + size - i, 1):
line[pos] = chr(j)
pos -= 2
# Next of mid until right extreme of the line.
pos = len(line) // 2 + 2
for j in range(start_char + 1, start_char + size - i, 1):
line[pos] = chr(j)
pos += 2
print("".join(line))
if __name__ == "__main__":
n = int(input())
print_rangoli(n)