forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrangoli.py
45 lines (34 loc) · 1.03 KB
/
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
"""Rangoli Model"""
# Prints a rangoli of size n
def print_rangoli(n):
"""Prints a rangoli of size n"""
# Width of the rangoli
width = 4 * n - 3
# String to be printed
string = ""
# Loop to print the rangoli
for i in range(1, n + 1):
for j in range(0, i):
string += chr(96 + n - j)
if len(string) < width:
string += "-"
for k in range(i - 1, 0, -1):
string += chr(97 + n - k)
if len(string) < width:
string += "-"
print(string.center(width, "-"))
string = ""
for i in range(n - 1, 0, -1):
for j in range(0, i):
string += chr(96 + n - j)
if len(string) < width:
string += "-"
for k in range(i - 1, 0, -1):
string += chr(97 + n - k)
if len(string) < width:
string += "-"
print(string.center(width, "-"))
string = ""
if __name__ == '__main__':
n = int(input())
print_rangoli(n)