Skip to content

Commit 04ded6e

Browse files
authored
Add files via upload
Updates from Python Basics for loop task
1 parent ff7de43 commit 04ded6e

1 file changed

Lines changed: 69 additions & 126 deletions

File tree

Python_Basics/Intro/PythonBasicsForLoops.ipynb

Lines changed: 69 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
},
3131
{
3232
"cell_type": "code",
33-
"execution_count": 44,
33+
"execution_count": 2,
3434
"metadata": {
3535
"collapsed": true
3636
},
@@ -42,7 +42,7 @@
4242
},
4343
{
4444
"cell_type": "code",
45-
"execution_count": 45,
45+
"execution_count": 3,
4646
"metadata": {},
4747
"outputs": [
4848
{
@@ -76,7 +76,7 @@
7676
},
7777
{
7878
"cell_type": "code",
79-
"execution_count": 46,
79+
"execution_count": 4,
8080
"metadata": {},
8181
"outputs": [
8282
{
@@ -115,7 +115,7 @@
115115
},
116116
{
117117
"cell_type": "code",
118-
"execution_count": 47,
118+
"execution_count": 5,
119119
"metadata": {
120120
"collapsed": true
121121
},
@@ -126,7 +126,7 @@
126126
},
127127
{
128128
"cell_type": "code",
129-
"execution_count": 48,
129+
"execution_count": 6,
130130
"metadata": {},
131131
"outputs": [
132132
{
@@ -150,7 +150,7 @@
150150
},
151151
{
152152
"cell_type": "code",
153-
"execution_count": 57,
153+
"execution_count": 7,
154154
"metadata": {},
155155
"outputs": [
156156
{
@@ -169,7 +169,7 @@
169169
},
170170
{
171171
"cell_type": "code",
172-
"execution_count": 58,
172+
"execution_count": 8,
173173
"metadata": {},
174174
"outputs": [
175175
{
@@ -196,7 +196,7 @@
196196
" 'the']"
197197
]
198198
},
199-
"execution_count": 58,
199+
"execution_count": 8,
200200
"metadata": {},
201201
"output_type": "execute_result"
202202
}
@@ -209,7 +209,7 @@
209209
},
210210
{
211211
"cell_type": "code",
212-
"execution_count": 59,
212+
"execution_count": 9,
213213
"metadata": {},
214214
"outputs": [
215215
{
@@ -218,7 +218,7 @@
218218
"0"
219219
]
220220
},
221-
"execution_count": 59,
221+
"execution_count": 9,
222222
"metadata": {},
223223
"output_type": "execute_result"
224224
}
@@ -231,7 +231,7 @@
231231
},
232232
{
233233
"cell_type": "code",
234-
"execution_count": 53,
234+
"execution_count": 10,
235235
"metadata": {
236236
"collapsed": true
237237
},
@@ -243,7 +243,7 @@
243243
},
244244
{
245245
"cell_type": "code",
246-
"execution_count": 54,
246+
"execution_count": 11,
247247
"metadata": {
248248
"collapsed": true
249249
},
@@ -257,7 +257,7 @@
257257
},
258258
{
259259
"cell_type": "code",
260-
"execution_count": 55,
260+
"execution_count": 12,
261261
"metadata": {},
262262
"outputs": [
263263
{
@@ -284,7 +284,7 @@
284284
" 'Up']"
285285
]
286286
},
287-
"execution_count": 55,
287+
"execution_count": 12,
288288
"metadata": {},
289289
"output_type": "execute_result"
290290
}
@@ -300,100 +300,26 @@
300300
"### Continue"
301301
]
302302
},
303+
{
304+
"cell_type": "markdown",
305+
"metadata": {},
306+
"source": [
307+
"continue keyword will move onto the next iteration of the loop <br>\n",
308+
"continue used for ignoring certain values, but not break out of loop "
309+
]
310+
},
303311
{
304312
"cell_type": "code",
305-
"execution_count": 56,
313+
"execution_count": 13,
306314
"metadata": {},
307315
"outputs": [
308316
{
309317
"data": {
310318
"text/plain": [
311-
"[2,\n",
312-
" 1,\n",
313-
" 4,\n",
314-
" 6,\n",
315-
" 7,\n",
316-
" 4,\n",
317-
" 4,\n",
318-
" 2,\n",
319-
" 2,\n",
320-
" 4,\n",
321-
" 4,\n",
322-
" 5,\n",
323-
" 2,\n",
324-
" 7,\n",
325-
" 6,\n",
326-
" 2,\n",
327-
" 7,\n",
328-
" 3,\n",
329-
" 3,\n",
330-
" 2,\n",
331-
" 5,\n",
332-
" 2,\n",
333-
" 3,\n",
334-
" 8,\n",
335-
" 1,\n",
336-
" 3,\n",
337-
" 1,\n",
338-
" 10,\n",
339-
" 5,\n",
340-
" 2,\n",
341-
" 4,\n",
342-
" 4,\n",
343-
" 5,\n",
344-
" 3,\n",
345-
" 2,\n",
346-
" 5,\n",
347-
" 4,\n",
348-
" 3,\n",
349-
" 1,\n",
350-
" 3,\n",
351-
" 2,\n",
352-
" 4,\n",
353-
" 3,\n",
354-
" 3,\n",
355-
" 5,\n",
356-
" 5,\n",
357-
" 3,\n",
358-
" 5,\n",
359-
" 2,\n",
360-
" 3,\n",
361-
" 8,\n",
362-
" 1,\n",
363-
" 5,\n",
364-
" 3,\n",
365-
" 7,\n",
366-
" 4,\n",
367-
" 3,\n",
368-
" 1,\n",
369-
" 3,\n",
370-
" 8,\n",
371-
" 2,\n",
372-
" 6,\n",
373-
" 4,\n",
374-
" 5,\n",
375-
" 2,\n",
376-
" 6,\n",
377-
" 2,\n",
378-
" 4,\n",
379-
" 5,\n",
380-
" 2,\n",
381-
" 4,\n",
382-
" 4,\n",
383-
" 3,\n",
384-
" 3,\n",
385-
" 2,\n",
386-
" 1,\n",
387-
" 6,\n",
388-
" 3,\n",
389-
" 3,\n",
390-
" 6,\n",
391-
" 2,\n",
392-
" 3,\n",
393-
" 3]"
319+
"[1, 4, 6, 7, 4, 4, 2, 2, 4, 4, 5, 2, 7, 6, 2, 7, 3, 3, 2]"
394320
]
395321
},
396-
"execution_count": 56,
322+
"execution_count": 13,
397323
"metadata": {},
398324
"output_type": "execute_result"
399325
}
@@ -406,56 +332,57 @@
406332
" if word == '':\n",
407333
" continue\n",
408334
" cleaned_list.append(len(word))\n",
409-
"cleaned_list"
335+
"cleaned_list[1:20]"
410336
]
411337
},
412338
{
413339
"cell_type": "markdown",
414340
"metadata": {},
415341
"source": [
416-
"### Break and Continue"
342+
"### Break"
417343
]
418344
},
419345
{
420-
"cell_type": "code",
421-
"execution_count": 43,
422-
"metadata": {
423-
"collapsed": true
424-
},
425-
"outputs": [],
346+
"cell_type": "markdown",
347+
"metadata": {},
426348
"source": [
427-
"### Break and Continue\n",
428-
"cleaned_list = []"
349+
"break keyword will completely break out of loop "
429350
]
430351
},
431352
{
432353
"cell_type": "code",
433-
"execution_count": null,
354+
"execution_count": 16,
434355
"metadata": {
435356
"collapsed": true
436357
},
437358
"outputs": [],
438359
"source": [
439-
"for word in text.split(' '): \n",
440-
" if word == '':\n",
441-
" continue\n",
442-
" cleaned_list.append(len(word))"
360+
"### Break and Continue\n",
361+
"cleaned_list = []"
443362
]
444363
},
445364
{
446365
"cell_type": "code",
447-
"execution_count": 10,
448-
"metadata": {
449-
"collapsed": true
450-
},
451-
"outputs": [],
366+
"execution_count": 17,
367+
"metadata": {},
368+
"outputs": [
369+
{
370+
"data": {
371+
"text/plain": [
372+
"[2, 1, 4, 6, 7, 0, 4, 4, 2, 2, 4]"
373+
]
374+
},
375+
"execution_count": 17,
376+
"metadata": {},
377+
"output_type": "execute_result"
378+
}
379+
],
452380
"source": [
453-
"# break and continue keywords when working with lists \n",
454-
"# break keyword will completely break out of loop \n",
455-
"\n",
456-
"# continue keyword will move onto the next iteration of the loop \n",
457-
"# continue used for ignoring certain values, but not break out of loop \n",
458-
"# completely\n"
381+
"for word in text.split(' '): \n",
382+
" if word == 'Warm':\n",
383+
" break\n",
384+
" cleaned_list.append(len(word))\n",
385+
"cleaned_list"
459386
]
460387
},
461388
{
@@ -513,6 +440,22 @@
513440
"### Task"
514441
]
515442
},
443+
{
444+
"cell_type": "markdown",
445+
"metadata": {},
446+
"source": [
447+
"1. Write a Python program which iterates through integers from 1 to 50 (using a for loop). For an integer that is even, append it to the list even_numbers. For an integer that is off, append it the list odd_numbers"
448+
]
449+
},
450+
{
451+
"cell_type": "code",
452+
"execution_count": null,
453+
"metadata": {
454+
"collapsed": true
455+
},
456+
"outputs": [],
457+
"source": []
458+
},
516459
{
517460
"cell_type": "markdown",
518461
"metadata": {},
@@ -577,7 +520,7 @@
577520
"name": "python",
578521
"nbconvert_exporter": "python",
579522
"pygments_lexer": "ipython3",
580-
"version": "3.6.1"
523+
"version": "3.6.0"
581524
}
582525
},
583526
"nbformat": 4,

0 commit comments

Comments
 (0)