Skip to content

Commit 0f7d74d

Browse files
authored
Add files via upload
1 parent 04ded6e commit 0f7d74d

1 file changed

Lines changed: 57 additions & 44 deletions

File tree

Python_Basics/Intro/PythonBasicsForLoops.ipynb

Lines changed: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -389,73 +389,104 @@
389389
"cell_type": "markdown",
390390
"metadata": {},
391391
"source": [
392-
"### Python 2 vs Python 3"
392+
"### Task (Introducing the range function)"
393+
]
394+
},
395+
{
396+
"cell_type": "markdown",
397+
"metadata": {},
398+
"source": [
399+
"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"
393400
]
394401
},
395402
{
396403
"cell_type": "code",
397-
"execution_count": 11,
404+
"execution_count": 18,
398405
"metadata": {
399406
"collapsed": true
400407
},
401408
"outputs": [],
402409
"source": [
403-
"# range\n",
404-
"# python 2 xrange and range are same\n",
405-
"# python 2 is list \n",
406-
"# in python 2 long ass list are slow\n",
407-
"# xrange long as number is faster because it is what is called a generator"
410+
"# Making empty lists to append even and odd numbers to. \n",
411+
"even_numbers = []\n",
412+
"odd_numbers = []\n",
413+
"\n",
414+
"for number in range(1,51):\n",
415+
" if number % 2 == 0:\n",
416+
" even_numbers.append(number)\n",
417+
" else: \n",
418+
" odd_numbers.append(number) "
408419
]
409420
},
410421
{
411-
"cell_type": "markdown",
422+
"cell_type": "code",
423+
"execution_count": 20,
412424
"metadata": {},
413-
"source": []
425+
"outputs": [
426+
{
427+
"name": "stdout",
428+
"output_type": "stream",
429+
"text": [
430+
"Even Numbers: [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50]\n"
431+
]
432+
}
433+
],
434+
"source": [
435+
"print(\"Even Numbers: \", even_numbers)"
436+
]
414437
},
415438
{
416-
"cell_type": "markdown",
439+
"cell_type": "code",
440+
"execution_count": 21,
417441
"metadata": {},
442+
"outputs": [
443+
{
444+
"name": "stdout",
445+
"output_type": "stream",
446+
"text": [
447+
"Odd Numbers: [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49]\n"
448+
]
449+
}
450+
],
418451
"source": [
419-
"**if this tutorial doesn't cover what you are looking for, please leave a comment on the youtube video and I will try to cover what you are interested in. (Please subscribe if you can!)**"
452+
"print(\"Odd Numbers: \", odd_numbers)"
420453
]
421454
},
422455
{
423456
"cell_type": "markdown",
424457
"metadata": {},
425458
"source": [
426-
"https://www.youtube.com/watch?v=JqGjkNzzU4s"
459+
"### Python 2 vs Python 3 (range function differences)"
427460
]
428461
},
429462
{
430-
"cell_type": "markdown",
431-
"metadata": {},
463+
"cell_type": "code",
464+
"execution_count": 23,
465+
"metadata": {
466+
"collapsed": true
467+
},
468+
"outputs": [],
432469
"source": [
433-
"Relevent questions to answer"
470+
"# python 2 xrange and Python 3 range are same (resembles a generator)\n",
471+
"# python 2 range generates a list\n",
472+
"\n",
473+
"# Importance: Long lists are slow"
434474
]
435475
},
436476
{
437477
"cell_type": "markdown",
438478
"metadata": {},
439479
"source": [
440-
"### Task"
480+
"**if this tutorial doesn't cover what you are looking for, please leave a comment on the youtube video and I will try to cover what you are interested in. (Please subscribe if you can!)**"
441481
]
442482
},
443483
{
444484
"cell_type": "markdown",
445485
"metadata": {},
446486
"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"
487+
"https://www.youtube.com/watch?v=JqGjkNzzU4s"
448488
]
449489
},
450-
{
451-
"cell_type": "code",
452-
"execution_count": null,
453-
"metadata": {
454-
"collapsed": true
455-
},
456-
"outputs": [],
457-
"source": []
458-
},
459490
{
460491
"cell_type": "markdown",
461492
"metadata": {},
@@ -483,24 +514,6 @@
483514
"source": [
484515
"https://www.quora.com/How-can-I-make-for-loops-work-in-Python"
485516
]
486-
},
487-
{
488-
"cell_type": "markdown",
489-
"metadata": {
490-
"collapsed": true
491-
},
492-
"source": [
493-
"Write a list comprehension that creates a list containing all of the numbers that are both exact squares and odd in the range 1 to 100."
494-
]
495-
},
496-
{
497-
"cell_type": "code",
498-
"execution_count": null,
499-
"metadata": {
500-
"collapsed": true
501-
},
502-
"outputs": [],
503-
"source": []
504517
}
505518
],
506519
"metadata": {

0 commit comments

Comments
 (0)