-
Notifications
You must be signed in to change notification settings - Fork 131
/
Copy pathrangoli.py
54 lines (49 loc) · 1.33 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
46
47
48
49
50
51
52
53
54
# define the input
def solve(n):
for i in range(n-1,-1,-1):
for j in range(i):
print(end="--")
for j in range(n-1,i,-1):
print(chr(j+97),end="-")
for j in range(i,n):
if j != n-1:
print(chr(j+97),end="-")
else:
print(chr(j+97),end="")
for j in range(2*i):
print(end="-")
print()
for i in range(1,n):
for j in range(i):
print(end="--")
for j in range(n-1,i,-1):
print(chr(j+97),end="-")
for j in range(i,n):
if j != n-1:
print(chr(j+97),end="-")
else:
print(chr(j+97),end="")
for j in range(2*i):
print(end="-")
print()
n = 8
solve(n)
##For testing purpose only
##You can change 'n' value to get different output
#Input = 8
#Output:
# --------------h--------------
# ------------h-g-h------------
# ----------h-g-f-g-h----------
# --------h-g-f-e-f-g-h--------
# ------h-g-f-e-d-e-f-g-h------
# ----h-g-f-e-d-c-d-e-f-g-h----
# --h-g-f-e-d-c-b-c-d-e-f-g-h--
# h-g-f-e-d-c-b-a-b-c-d-e-f-g-h
# --h-g-f-e-d-c-b-c-d-e-f-g-h--
# ----h-g-f-e-d-c-d-e-f-g-h----
# ------h-g-f-e-d-e-f-g-h------
# --------h-g-f-e-f-g-h--------
# ----------h-g-f-g-h----------
# ------------h-g-h------------
# --------------h--------------