Skip to content

Commit e3c390a

Browse files
committed
Python problems for beginners
1 parent 9cf3b5d commit e3c390a

File tree

1 file changed

+243
-0
lines changed

1 file changed

+243
-0
lines changed
Lines changed: 243 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,243 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"## Python problems for beginners"
8+
]
9+
},
10+
{
11+
"cell_type": "markdown",
12+
"metadata": {},
13+
"source": [
14+
"## Problem 1 Triangle\n",
15+
"\n",
16+
"Write a simple program that demonstrate star pattern in Python 3.x for any n:\n",
17+
"\n",
18+
"Example n=5\n",
19+
"\n",
20+
" * \n",
21+
" * * \n",
22+
" * * * \n",
23+
" * * * * \n",
24+
" * * * * * "
25+
]
26+
},
27+
{
28+
"cell_type": "code",
29+
"execution_count": 20,
30+
"metadata": {},
31+
"outputs": [
32+
{
33+
"name": "stdout",
34+
"output_type": "stream",
35+
"text": [
36+
"\n",
37+
"* \n",
38+
"* * \n",
39+
"* * * \n",
40+
"* * * * \n",
41+
"* * * * * \n"
42+
]
43+
}
44+
],
45+
"source": [
46+
"n = 5\n",
47+
"\n",
48+
"for i in range(0, n+1):\n",
49+
" print('* ' * i)"
50+
]
51+
},
52+
{
53+
"cell_type": "code",
54+
"execution_count": 22,
55+
"metadata": {},
56+
"outputs": [
57+
{
58+
"name": "stdout",
59+
"output_type": "stream",
60+
"text": [
61+
"7\n"
62+
]
63+
}
64+
],
65+
"source": [
66+
"n = n +2\n",
67+
"print(n)"
68+
]
69+
},
70+
{
71+
"cell_type": "code",
72+
"execution_count": 33,
73+
"metadata": {},
74+
"outputs": [
75+
{
76+
"name": "stdout",
77+
"output_type": "stream",
78+
"text": [
79+
"ddd"
80+
]
81+
}
82+
],
83+
"source": [
84+
"for x in ['a', 's', 'd']:\n",
85+
" print('d', end='')"
86+
]
87+
},
88+
{
89+
"cell_type": "code",
90+
"execution_count": 31,
91+
"metadata": {},
92+
"outputs": [
93+
{
94+
"data": {
95+
"text/plain": [
96+
"[3, 6, 9]"
97+
]
98+
},
99+
"execution_count": 31,
100+
"metadata": {},
101+
"output_type": "execute_result"
102+
}
103+
],
104+
"source": [
105+
"list(range(3,10,3))"
106+
]
107+
},
108+
{
109+
"cell_type": "markdown",
110+
"metadata": {},
111+
"source": [
112+
"## Problem 2 Triangle with numbers\n",
113+
"\n",
114+
"Write a simple program that demonstrate triangle (with numbers 0..n per line) in Python 3.x for any n:\n",
115+
"\n",
116+
"Example n=4\n",
117+
"\n",
118+
" 1 \n",
119+
" 1 2 \n",
120+
" 1 2 3 \n",
121+
" 1 2 3 4"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": 38,
127+
"metadata": {},
128+
"outputs": [
129+
{
130+
"name": "stdout",
131+
"output_type": "stream",
132+
"text": [
133+
"x\n",
134+
"\n",
135+
"x\n",
136+
"y\n",
137+
"1 \n",
138+
"x\n",
139+
"y\n",
140+
"1 y\n",
141+
"2 \n",
142+
"x\n",
143+
"y\n",
144+
"1 y\n",
145+
"2 y\n",
146+
"3 \n",
147+
"x\n",
148+
"y\n",
149+
"1 y\n",
150+
"2 y\n",
151+
"3 y\n",
152+
"4 \n"
153+
]
154+
}
155+
],
156+
"source": [
157+
"n = 4\n",
158+
"\n",
159+
"for i in range(0, n+1):\n",
160+
" for j in range(1, i + 1):\n",
161+
" print(j, end=' ')\n",
162+
" print()"
163+
]
164+
},
165+
{
166+
"cell_type": "markdown",
167+
"metadata": {},
168+
"source": [
169+
"## Homework 1 Triangle with letters \n",
170+
"\n",
171+
"Write a simple program that demonstrate triangle (with consequtive letters) in Python 3.x for any n:\n",
172+
"\n",
173+
"Example n=4\n",
174+
"\n",
175+
" A \n",
176+
" B C \n",
177+
" D E F \n",
178+
" G H I J \n",
179+
" K L M N O "
180+
]
181+
},
182+
{
183+
"cell_type": "markdown",
184+
"metadata": {},
185+
"source": [
186+
"## Homework 2 Diagonal of numbers\n",
187+
"\n",
188+
"Write a simple program that demonstrate diagonal pattern in Python 3.x for any n:\n",
189+
"\n",
190+
"Example n=4\n",
191+
"\n",
192+
"0\n",
193+
" 1\n",
194+
" 2\n",
195+
" 3\n",
196+
" 4"
197+
]
198+
},
199+
{
200+
"cell_type": "markdown",
201+
"metadata": {},
202+
"source": [
203+
"## Homework 3 Pyramid\n",
204+
"\n",
205+
"Write a simple program that demonstrate pyramid pattern in Python 3.x for any n:\n",
206+
"\n",
207+
"Example n=3\n",
208+
"\n",
209+
" * \n",
210+
" * * * \n",
211+
" * * * * * "
212+
]
213+
},
214+
{
215+
"cell_type": "code",
216+
"execution_count": null,
217+
"metadata": {},
218+
"outputs": [],
219+
"source": []
220+
}
221+
],
222+
"metadata": {
223+
"kernelspec": {
224+
"display_name": "Python 3",
225+
"language": "python",
226+
"name": "python3"
227+
},
228+
"language_info": {
229+
"codemirror_mode": {
230+
"name": "ipython",
231+
"version": 3
232+
},
233+
"file_extension": ".py",
234+
"mimetype": "text/x-python",
235+
"name": "python",
236+
"nbconvert_exporter": "python",
237+
"pygments_lexer": "ipython3",
238+
"version": "3.6.7"
239+
}
240+
},
241+
"nbformat": 4,
242+
"nbformat_minor": 2
243+
}

0 commit comments

Comments
 (0)