Skip to content

Commit f124613

Browse files
committed
updated coding challenges
1 parent 2ee9ecc commit f124613

13 files changed

+97981
-3082
lines changed

Coding challenges/Day_1.ipynb renamed to Coding Challenges/Day_1_Python Warmup.ipynb

Lines changed: 95 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,105 @@
350350
"* Print the first three days of the week"
351351
]
352352
},
353+
{
354+
"cell_type": "markdown",
355+
"metadata": {},
356+
"source": [
357+
"## Loops\n",
358+
"\n",
359+
"Loops are a way to repeatedly execute some code. Here's an example:\n"
360+
]
361+
},
353362
{
354363
"cell_type": "code",
355364
"execution_count": null,
356365
"metadata": {},
357366
"outputs": [],
358-
"source": []
367+
"source": [
368+
"planets = ['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune']\n",
369+
"for planet in planets:\n",
370+
" print(planet, end=' ') # print all on same line\n"
371+
]
372+
},
373+
{
374+
"cell_type": "markdown",
375+
"metadata": {},
376+
"source": [
377+
"The for loop specifies\n",
378+
"\n",
379+
" * the variable name to use (in this case, planet)\n",
380+
" \n",
381+
" * the set of values to loop over (in this case, planets)\n",
382+
"\n",
383+
"You use the word \"in\" to link them together.\n",
384+
"\n",
385+
"The object to the right of the \"in\" can be any object that supports iteration. Basically, if it can be thought of as a group of things, you can probably loop over it. In addition to lists, we can iterate over the elements of a tuple:\n"
386+
]
387+
},
388+
{
389+
"cell_type": "code",
390+
"execution_count": null,
391+
"metadata": {},
392+
"outputs": [],
393+
"source": [
394+
"multiplicands = [2, 2, 2, 3, 3, 5]\n",
395+
"product = 1\n",
396+
"for mult in multiplicands:\n",
397+
" product = product * mult\n",
398+
"product\n"
399+
]
400+
},
401+
{
402+
"cell_type": "markdown",
403+
"metadata": {},
404+
"source": [
405+
"\n",
406+
"You can even loop through each character in a string:\n"
407+
]
408+
},
409+
{
410+
"cell_type": "code",
411+
"execution_count": null,
412+
"metadata": {},
413+
"outputs": [],
414+
"source": [
415+
"s = 'steganograpHy is the practicE of conceaLing a file, message, image, or video within another fiLe, message, image, Or video.'\n",
416+
"msg = ''\n",
417+
"# print all the uppercase letters in s, one at a time\n",
418+
"for char in s:\n",
419+
" if char.isupper():\n",
420+
" print(char, end='') "
421+
]
422+
},
423+
{
424+
"cell_type": "markdown",
425+
"metadata": {},
426+
"source": [
427+
"## Do it yourself\n",
428+
"\n",
429+
"## Task 1\n",
430+
"\n",
431+
"* Create a list of all the 7 days of the weeks and store it in the variable `weekdays`.\n",
432+
"\n",
433+
"* Iterate through the first 5 days of the week stored in the variable `weekdays` and print them.\n",
434+
"\n",
435+
"\n",
436+
"\n",
437+
"## Task 2\n",
438+
"\n",
439+
"* Iterate the elements in the list defined below, divide each number by 5 and print quotient for each of the element.\n",
440+
"\n",
441+
"elements = [10,20,30,40,50]\n"
442+
]
443+
},
444+
{
445+
"cell_type": "code",
446+
"execution_count": null,
447+
"metadata": {},
448+
"outputs": [],
449+
"source": [
450+
"# write the code here\n"
451+
]
359452
}
360453
],
361454
"metadata": {
@@ -374,7 +467,7 @@
374467
"name": "python",
375468
"nbconvert_exporter": "python",
376469
"pygments_lexer": "ipython3",
377-
"version": "3.7.6"
470+
"version": "3.7.4"
378471
}
379472
},
380473
"nbformat": 4,

0 commit comments

Comments
 (0)