diff --git a/lectures/Day_3.ipynb b/lectures/Day_3.ipynb index b024b94..438023b 100644 --- a/lectures/Day_3.ipynb +++ b/lectures/Day_3.ipynb @@ -82,7 +82,7 @@ } }, "source": [ - "## Tuples (Q 1&2)\n", + "### Tuples (Q 1&2)\n", "\n", "__1. Which of the following variables are of the type tuple?__ \n", "`a = (1, 2, 3, 4)` \n", @@ -104,7 +104,7 @@ "cell_type": "markdown", "metadata": { "slideshow": { - "slide_type": "fragment" + "slide_type": "slide" } }, "source": [ @@ -129,7 +129,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, "outputs": [], "source": [ "myList[2] = 4\n", @@ -139,7 +143,11 @@ { "cell_type": "code", "execution_count": null, - "metadata": {}, + "metadata": { + "slideshow": { + "slide_type": "fragment" + } + }, "outputs": [], "source": [ "myTuple[2] = 4" @@ -721,12 +729,12 @@ } }, "source": [ - "## Day 3, Exercise 1 (~20 min)\n", + "## Day 3, Exercise 1 (~30 min)\n", "### Find the number of unique genres in the file `250.imdb`\n", "\n", "\"Drawing\" \n", "\n", - "- Canvas -> Modules -> Day 3 -> IMDb exercise -> 1 \n", + "- Canvas -> Modules -> Day 3 -> IMDb exercise - day 3 -> 1 \n", "\n", "\n", "\n", @@ -815,7 +823,7 @@ "\n", "- A dictionary is an unordered, mutable collection of key-value pairs. \n", "- Dictionaries are mutable\n", - "- Each key in a dictionary must be unique and immutable, while the values associated with keys can be of any data type and can be duplicated\n", + "- Each key in a dictionary must be unique and immutable (the same as `set`), while the values associated with keys can be of any data type and can be duplicated\n", "\n", "
\n", "\"Drawing\" " @@ -946,6 +954,13 @@ " 'biography': 25}" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "markdown", "metadata": { @@ -1003,7 +1018,7 @@ "- #### (Extra) What is the average length of the movies (in hours and minutes) in each genre?\n", "\n", "\n", - "- Canvas -> Modules -> Day 3 -> IMDb exercise -> 2&3 \n", + "- Canvas -> Modules -> Day 3 -> IMDb exercise - day 3 -> 2&3 \n", "___\n", "#### Take a break after the exercise (~10 min)\n", "\n", @@ -1116,7 +1131,6 @@ "cell_type": "code", "execution_count": null, "metadata": { - "scrolled": true, "slideshow": { "slide_type": "skip" } @@ -1286,7 +1300,34 @@ "# Calculate the average duration of movies in the genre 'drama'\n", "genre = \"drama\"\n", "average = sum(genreDict[genre])/len(genreDict[genre]) # calculate average length per genre\n", - "hours = int(average/3600) # format seconds to hours\n", + "hours = int(average/3600) # format seconds to hours\n", + "minutes = (average - (3600*hours))/60 # format seconds to minutes\n", + "reformattedTime = str(hours)+'h'+str(round(minutes))+'min'\n", + "print('The average length for movies in genre '+ genre +\\\n", + " ' is '+ reformattedTime)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "#### Now let convert this code into a function" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Calculate the average duration of movies in the genre 'drama'\n", + "genre = \"drama\"\n", + "average = sum(genreDict[genre])/len(genreDict[genre]) # calculate average length per genre\n", + "hours = int(average/3600) # format seconds to hours\n", "minutes = (average - (3600*hours))/60 # format seconds to minutes\n", "reformattedTime = str(hours)+'h'+str(round(minutes))+'min'\n", "print('The average length for movies in genre '+ genre +\\\n", @@ -1753,7 +1794,7 @@ } }, "source": [ - "### Try out `sys.argv`\n", + "### Try out `sys.argv` (~5 min)\n", "\n", "Python script is called `print_argv.py` and can be found in the downloads folder\n", "\n", @@ -1765,6 +1806,39 @@ "```" ] }, + { + "cell_type": "markdown", + "metadata": { + "slideshow": { + "slide_type": "slide" + } + }, + "source": [ + "#### If you don't have the file print_argv.py, copy the following code and save it in a file called print_argv.py " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "slideshow": { + "slide_type": "-" + } + }, + "outputs": [], + "source": [ + "#!/usr/bin/env python\n", + "import sys\n", + "\n", + "print(\"size of sys.argv = \", len(sys.argv))\n", + "print(\"program_name = \", sys.argv[0])\n", + "\n", + "counter = 1\n", + "while counter < len(sys.argv):\n", + " print(\"arg\" + str(counter) + \" = \", sys.argv[counter])\n", + " counter += 1" + ] + }, { "cell_type": "markdown", "metadata": { @@ -2082,7 +2156,7 @@ "### Day 3, Exercise 4 (~30 min)\n", "- #### Restructure and write the output to a new file\n", "\n", - "- Canvas -> Modules -> Day 3 -> IMDb exercise -> 4\n", + "- Canvas -> Modules -> Day 3 -> IMDb exercise - day 3 -> 4\n", "- Work in pairs\n", "\n", "#### PyQuiz 3.2 \n", diff --git a/lectures/Day_3.slides.embedded.html b/lectures/Day_3.slides.embedded.html index e1680fc..62574d7 100644 --- a/lectures/Day_3.slides.embedded.html +++ b/lectures/Day_3.slides.embedded.html @@ -14704,13 +14704,13 @@

Quiz: Review Day 2
-

Tuples (Q 1&2)

1. Which of the following variables are of the type tuple?
+

Tuples (Q 1&2)

1. Which of the following variables are of the type tuple?
a = (1, 2, 3, 4)
a = ([1, 2], 'a', 'b')

-
+
+
+ -
+
+
+

diff --git a/lectures/Day_3.slides.pdf b/lectures/Day_3.slides.pdf index 1c27417..c281e32 100644 Binary files a/lectures/Day_3.slides.pdf and b/lectures/Day_3.slides.pdf differ