Skip to content

Commit aee9bd7

Browse files
committed
pattern_functions
1 parent d0b550c commit aee9bd7

File tree

2 files changed

+576
-0
lines changed

2 files changed

+576
-0
lines changed
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 8,
6+
"id": "11bcede4",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"def print_pattern(direction='triangle'):\n",
11+
" if direction == 'triangle':\n",
12+
" for i in range(1, 11):\n",
13+
" print(' ' * (10-i) + '* ' * i)\n",
14+
"\n",
15+
" elif direction == 'right_triangle':\n",
16+
" for i in range(1, 11):\n",
17+
" print('* ' * i)\n",
18+
"\n",
19+
" elif direction == 'left_triangle':\n",
20+
" for i in range(10, 0, -1):\n",
21+
" print('* ' * i)\n",
22+
"\n",
23+
" elif direction == 'reverse_triangle':\n",
24+
" for i in range(6, 0, -1):\n",
25+
" print(' ' * (6-i) + '* ' * i)\n",
26+
" \n",
27+
" elif direction == 'reverse_right_triangle':\n",
28+
" for i in range(10, 0, -1):\n",
29+
" print('* ' * i)\n",
30+
" \n",
31+
"\n",
32+
" elif direction == 'reverse_left_triangle':\n",
33+
" for i in range(10, 0, -1):\n",
34+
" print(' ' * (10-i) + '* ' * i)\n",
35+
"\n",
36+
" elif direction == 'right_py_triangle':\n",
37+
" for i in range(1, 11):\n",
38+
" print('* ' * i)\n",
39+
" for i in range(11, 0, -1):\n",
40+
" print('* ' * i)\n",
41+
"\n",
42+
" elif direction == 'left_py_triangle':\n",
43+
" for i in range(10, 0, -1):\n",
44+
" print('* ' * i)\n",
45+
" for i in range(10, 0, -1):\n",
46+
" print(' ' * (10-i) + '* ' * i)\n",
47+
"\n",
48+
" else:\n",
49+
" print('please give correct direction.')"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 9,
55+
"id": "e7ddffa2",
56+
"metadata": {},
57+
"outputs": [
58+
{
59+
"name": "stdout",
60+
"output_type": "stream",
61+
"text": [
62+
" * \n",
63+
" * * \n",
64+
" * * * \n",
65+
" * * * * \n",
66+
" * * * * * \n",
67+
" * * * * * * \n",
68+
" * * * * * * * \n",
69+
" * * * * * * * * \n",
70+
" * * * * * * * * * \n",
71+
"* * * * * * * * * * \n"
72+
]
73+
}
74+
],
75+
"source": [
76+
"print_pattern(direction='triangle')"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": 10,
82+
"id": "7596ce3e",
83+
"metadata": {},
84+
"outputs": [
85+
{
86+
"name": "stdout",
87+
"output_type": "stream",
88+
"text": [
89+
"* * * * * * * * * * \n",
90+
"* * * * * * * * * \n",
91+
"* * * * * * * * \n",
92+
"* * * * * * * \n",
93+
"* * * * * * \n",
94+
"* * * * * \n",
95+
"* * * * \n",
96+
"* * * \n",
97+
"* * \n",
98+
"* \n",
99+
"* * * * * * * * * * \n",
100+
" * * * * * * * * * \n",
101+
" * * * * * * * * \n",
102+
" * * * * * * * \n",
103+
" * * * * * * \n",
104+
" * * * * * \n",
105+
" * * * * \n",
106+
" * * * \n",
107+
" * * \n",
108+
" * \n"
109+
]
110+
}
111+
],
112+
"source": [
113+
"print_pattern(direction='left_py_triangle')"
114+
]
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": 11,
119+
"id": "c7f5c4bc",
120+
"metadata": {},
121+
"outputs": [
122+
{
123+
"name": "stdout",
124+
"output_type": "stream",
125+
"text": [
126+
"* * * * * * * * * * \n",
127+
"* * * * * * * * * \n",
128+
"* * * * * * * * \n",
129+
"* * * * * * * \n",
130+
"* * * * * * \n",
131+
"* * * * * \n",
132+
"* * * * \n",
133+
"* * * \n",
134+
"* * \n",
135+
"* \n"
136+
]
137+
}
138+
],
139+
"source": [
140+
"print_pattern(direction='reverse_right_triangle')"
141+
]
142+
},
143+
{
144+
"cell_type": "code",
145+
"execution_count": 12,
146+
"id": "145f004b",
147+
"metadata": {},
148+
"outputs": [
149+
{
150+
"name": "stdout",
151+
"output_type": "stream",
152+
"text": [
153+
"* \n",
154+
"* * \n",
155+
"* * * \n",
156+
"* * * * \n",
157+
"* * * * * \n",
158+
"* * * * * * \n",
159+
"* * * * * * * \n",
160+
"* * * * * * * * \n",
161+
"* * * * * * * * * \n",
162+
"* * * * * * * * * * \n",
163+
"* * * * * * * * * * * \n",
164+
"* * * * * * * * * * \n",
165+
"* * * * * * * * * \n",
166+
"* * * * * * * * \n",
167+
"* * * * * * * \n",
168+
"* * * * * * \n",
169+
"* * * * * \n",
170+
"* * * * \n",
171+
"* * * \n",
172+
"* * \n",
173+
"* \n"
174+
]
175+
}
176+
],
177+
"source": [
178+
"print_pattern(direction='right_py_triangle')"
179+
]
180+
},
181+
{
182+
"cell_type": "code",
183+
"execution_count": 13,
184+
"id": "05470439",
185+
"metadata": {},
186+
"outputs": [
187+
{
188+
"name": "stdout",
189+
"output_type": "stream",
190+
"text": [
191+
"* * * * * * * * * * \n",
192+
" * * * * * * * * * \n",
193+
" * * * * * * * * \n",
194+
" * * * * * * * \n",
195+
" * * * * * * \n",
196+
" * * * * * \n",
197+
" * * * * \n",
198+
" * * * \n",
199+
" * * \n",
200+
" * \n"
201+
]
202+
}
203+
],
204+
"source": [
205+
"print_pattern(direction='reverse_left_triangle')"
206+
]
207+
},
208+
{
209+
"cell_type": "code",
210+
"execution_count": 14,
211+
"id": "25bfb625",
212+
"metadata": {},
213+
"outputs": [
214+
{
215+
"name": "stdout",
216+
"output_type": "stream",
217+
"text": [
218+
"* \n",
219+
"* * \n",
220+
"* * * \n",
221+
"* * * * \n",
222+
"* * * * * \n",
223+
"* * * * * * \n",
224+
"* * * * * * * \n",
225+
"* * * * * * * * \n",
226+
"* * * * * * * * * \n",
227+
"* * * * * * * * * * \n"
228+
]
229+
}
230+
],
231+
"source": [
232+
"print_pattern(direction='right_triangle')"
233+
]
234+
},
235+
{
236+
"cell_type": "code",
237+
"execution_count": 15,
238+
"id": "56a3286f",
239+
"metadata": {},
240+
"outputs": [
241+
{
242+
"name": "stdout",
243+
"output_type": "stream",
244+
"text": [
245+
"* * * * * * \n",
246+
" * * * * * \n",
247+
" * * * * \n",
248+
" * * * \n",
249+
" * * \n",
250+
" * \n"
251+
]
252+
}
253+
],
254+
"source": [
255+
"print_pattern(direction='reverse_triangle')"
256+
]
257+
},
258+
{
259+
"cell_type": "code",
260+
"execution_count": null,
261+
"id": "5302c1e5",
262+
"metadata": {},
263+
"outputs": [],
264+
"source": []
265+
}
266+
],
267+
"metadata": {
268+
"kernelspec": {
269+
"display_name": "Python 3 (ipykernel)",
270+
"language": "python",
271+
"name": "python3"
272+
},
273+
"language_info": {
274+
"codemirror_mode": {
275+
"name": "ipython",
276+
"version": 3
277+
},
278+
"file_extension": ".py",
279+
"mimetype": "text/x-python",
280+
"name": "python",
281+
"nbconvert_exporter": "python",
282+
"pygments_lexer": "ipython3",
283+
"version": "3.9.12"
284+
}
285+
},
286+
"nbformat": 4,
287+
"nbformat_minor": 5
288+
}

0 commit comments

Comments
 (0)