-
Notifications
You must be signed in to change notification settings - Fork 2
/
Pattern-Printer.py
142 lines (140 loc) · 2.09 KB
/
Pattern-Printer.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
'''
$
@@
$$$
@@@@
$$$$$
'''
# Simple For Loop
for i in range(1,6):
if i%2==0:
print("@"*i,end='')
else:
print("$"*i,end='')
print('')
# Nested For Loop
for i in range(1,6):
for j in range(1,i+1):
if i%2==0:
print("@",end='')
else:
print("$",end='')
print('')
'''
A
AB
ABC
ABCD
ABCDE
'''
for i in range(65,70):
for j in range(65,i+1):
print(chr(j),end='')
print('')
'''
A
BAB
CBABC
DCBABCD
'''
for i in range(0,4):
for sp in range(6,i,-1):
print(' ',end='')
for d in range(65+i,64,-1):
print(chr(d),end='')
for a in range(66,66+i,1):
print(chr(a),end='')
print('')
'''
A
ABA
ABCBA
ABCDCBA
'''
for i in range(0,4):
for sp in range(i,6):
print(' ',end='')
for d in range(65,65+i):
print(chr(d),end='')
for a in range(65+i,64,-1):
print(chr(a),end='')
print('')
'''
A
B C
D E F
G H I J
K L M N O
'''
n=65
for i in range(0,5):
for sp in range(i,6):
print(' ',end='')
for j in range(0,i+1):
print(chr(n),end=' ')
n+=1
print('')
'''
Given string 'abc', print following patterns:
a. a
bb
ccc
b. a
ab
abc
c. abc
ab
a
d. cba
cb
c
e. a
abab
abcabcabc
'''
str='abc'
# 1st Sub Part
for i in range(0,3):
for j in range(0,i+1):
print(str[i],end='')
print()
# 2nd Sub Part
for i in range(1,4):
for j in range(0,i):
print(str[j],end='')
print()
# 3rd Sub Part
for i in range(3,0,-1):
for j in range(0,i):
print(str[j],end='')
print()
# 4th Sub Part
for i in range(-1,2,1):
for j in range(2,i,-1):
print(str[j],end='')
print()
# 5th Sub Part
for i in range(1,4):
for r in range(1,i+1):
for j in range(0,i):
print(str[j],end='')
print()
'''
e
cec
aceca
racecar
'''
s1='r a c e c a r'
for i in range(0,7,2):
print(' '*(6-i),end=' ')
print(s1[6-i:7+i])
'''
di
ndia
indian
'''
s2='i n d i a n'
for i in range(0,7,2):
print(' '*(6-i),end=' ')
print(s2[6-i:7+(i-1)])