Skip to content

Commit a3d9adf

Browse files
authored
Add files via upload
1 parent 86be1bb commit a3d9adf

File tree

1 file changed

+225
-0
lines changed

1 file changed

+225
-0
lines changed

Loops in Python? lecture 3.ipynb

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# While Loop"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 5,
13+
"metadata": {},
14+
"outputs": [],
15+
"source": [
16+
"i = 1"
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": 18,
22+
"metadata": {},
23+
"outputs": [
24+
{
25+
"name": "stdout",
26+
"output_type": "stream",
27+
"text": [
28+
"1\n",
29+
"2\n",
30+
"3\n",
31+
"4\n",
32+
"5\n",
33+
"6\n",
34+
"7\n",
35+
"8\n",
36+
"9\n",
37+
"finally finished\n"
38+
]
39+
}
40+
],
41+
"source": [
42+
"while i < 10:\n",
43+
" print(i)\n",
44+
" i = i + 1\n",
45+
" \n",
46+
"else:\n",
47+
" print(\"finally finished\")"
48+
]
49+
},
50+
{
51+
"cell_type": "code",
52+
"execution_count": 6,
53+
"metadata": {},
54+
"outputs": [],
55+
"source": [
56+
"j = 1"
57+
]
58+
},
59+
{
60+
"cell_type": "code",
61+
"execution_count": 7,
62+
"metadata": {},
63+
"outputs": [
64+
{
65+
"name": "stdout",
66+
"output_type": "stream",
67+
"text": [
68+
"1\n",
69+
"2\n",
70+
"3\n"
71+
]
72+
}
73+
],
74+
"source": [
75+
"while j < 6:\n",
76+
" print(j)\n",
77+
" if j == 3:\n",
78+
" break\n",
79+
" j+= 1"
80+
]
81+
},
82+
{
83+
"cell_type": "markdown",
84+
"metadata": {},
85+
"source": [
86+
"# For Loop"
87+
]
88+
},
89+
{
90+
"cell_type": "code",
91+
"execution_count": 12,
92+
"metadata": {},
93+
"outputs": [
94+
{
95+
"name": "stdout",
96+
"output_type": "stream",
97+
"text": [
98+
"50\n",
99+
"60\n",
100+
"70\n",
101+
"80\n",
102+
"90\n"
103+
]
104+
}
105+
],
106+
"source": [
107+
"for x in range(50,100,10):\n",
108+
" print x"
109+
]
110+
},
111+
{
112+
"cell_type": "code",
113+
"execution_count": 13,
114+
"metadata": {},
115+
"outputs": [],
116+
"source": [
117+
"myList = [\"banana\", \"apple\", \"mango\"]"
118+
]
119+
},
120+
{
121+
"cell_type": "code",
122+
"execution_count": 14,
123+
"metadata": {},
124+
"outputs": [
125+
{
126+
"name": "stdout",
127+
"output_type": "stream",
128+
"text": [
129+
"banana\n",
130+
"apple\n",
131+
"mango\n"
132+
]
133+
}
134+
],
135+
"source": [
136+
"for x in myList:\n",
137+
" print x"
138+
]
139+
},
140+
{
141+
"cell_type": "code",
142+
"execution_count": 15,
143+
"metadata": {},
144+
"outputs": [
145+
{
146+
"name": "stdout",
147+
"output_type": "stream",
148+
"text": [
149+
"a\n",
150+
"l\n",
151+
"o\n",
152+
"k\n",
153+
" \n",
154+
"m\n",
155+
"i\n",
156+
"s\n",
157+
"h\n",
158+
"r\n",
159+
"a\n"
160+
]
161+
}
162+
],
163+
"source": [
164+
"for x in \"alok mishra\":\n",
165+
" print x"
166+
]
167+
},
168+
{
169+
"cell_type": "code",
170+
"execution_count": 17,
171+
"metadata": {},
172+
"outputs": [
173+
{
174+
"name": "stdout",
175+
"output_type": "stream",
176+
"text": [
177+
"0\n",
178+
"1\n",
179+
"2\n",
180+
"3\n",
181+
"4\n",
182+
"5\n",
183+
"6\n",
184+
"finally finished\n"
185+
]
186+
}
187+
],
188+
"source": [
189+
"for x in range(7):\n",
190+
" print x\n",
191+
"\n",
192+
"else:\n",
193+
" print(\"finally finished\")"
194+
]
195+
},
196+
{
197+
"cell_type": "code",
198+
"execution_count": null,
199+
"metadata": {},
200+
"outputs": [],
201+
"source": []
202+
}
203+
],
204+
"metadata": {
205+
"kernelspec": {
206+
"display_name": "Python 2",
207+
"language": "python",
208+
"name": "python2"
209+
},
210+
"language_info": {
211+
"codemirror_mode": {
212+
"name": "ipython",
213+
"version": 2
214+
},
215+
"file_extension": ".py",
216+
"mimetype": "text/x-python",
217+
"name": "python",
218+
"nbconvert_exporter": "python",
219+
"pygments_lexer": "ipython2",
220+
"version": "2.7.16"
221+
}
222+
},
223+
"nbformat": 4,
224+
"nbformat_minor": 2
225+
}

0 commit comments

Comments
 (0)