From 2e2a4dd7d440139edf703fb250099e2db477a5d4 Mon Sep 17 00:00:00 2001 From: "Kenneth C. Kleissl" Date: Fri, 10 Jan 2020 10:24:19 +0100 Subject: [PATCH 1/2] minor tweaks and typo fixes --- .../Session 3 - Exercise Solutions.ipynb | 4 +-- .../Session 3 - Functions.ipynb | 28 +++++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/Session 3 - Functions/Session 3 - Exercise Solutions.ipynb b/Session 3 - Functions/Session 3 - Exercise Solutions.ipynb index 8b11853..87e73e0 100644 --- a/Session 3 - Functions/Session 3 - Exercise Solutions.ipynb +++ b/Session 3 - Functions/Session 3 - Exercise Solutions.ipynb @@ -374,7 +374,7 @@ "source": [ "* **Note 1:** Call to function `circle_area` defined in Exercise instead of defining the expression `pi * r**2 / 4` again. The concept of functions calling other functions can be used to make modular programs that are easy to follow and maintain. Each function only needs to do a small thing in itself.\n", "\n", - "* **Note 2:** The input parameter when the function was *defined* was a list called `radii`, but the when the function was *called*, the input list was called `list_of_radii`. Thus, the input parameters passed into a function do not need to have the same name as when the function is defined." + "* **Note 2:** The input parameter when the function was *defined* was a list called `radii`, but when the function was *called*, the input list was called `list_of_radii`. Thus, the input parameters passed into a function do not need to have the same name as when the function is defined." ] }, { @@ -814,7 +814,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.7.5" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/Session 3 - Functions/Session 3 - Functions.ipynb b/Session 3 - Functions/Session 3 - Functions.ipynb index eff03b4..be20529 100644 --- a/Session 3 - Functions/Session 3 - Functions.ipynb +++ b/Session 3 - Functions/Session 3 - Functions.ipynb @@ -292,7 +292,7 @@ }, "source": [ "\n", - "# 3. - Functions\n", + "# 3. Functions\n", "A **function** is a block of code that is first defined, and thereafter can be called to run as many times as needed. A function might have arguments, some of which can be optional if a default value is specified.\n", "\n", "A function is called by parentheses: `function_name()`. Arguments are placed inside the parentehes and comma separated if there are more than one.\n", @@ -447,10 +447,20 @@ }, { "cell_type": "markdown", - "metadata": { - "cell_style": "center" - }, + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 3)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ + "## Examples of built-in functions\n", "### Using `enumerate` for looping in index/value pairs\n", "The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:" ] @@ -612,7 +622,7 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "`zip` stops when the shortest iterable is exhausted. So if if `c` is removed from the first string in the example above, we have iterables of lengths 2, 3 and 3. \n", + "`zip` stops when the shortest iterable is exhausted. So if `c` is removed from the first string in the example above, we have iterables of lengths 2, 3 and 3. \n", "\n", "Thus, only two iterations are performed:" ] @@ -692,7 +702,7 @@ " # Your code goes here\n", "~~~\n", "\n", - "Try to call it to see if it works. If you want to access `pi` to avoid typing it out yourself, put the line `from math import pi` at some point before calling the `circle_area` function.\n" + "Try to call it to see if it works. If you want to access `pi` to avoid typing it out yourself, put the line `from math import pi` at some point before defining the `circle_area` function.\n" ] }, { @@ -700,7 +710,7 @@ "metadata": {}, "source": [ "# Exercise 2\n", - "Write a function that takes a list `radii` as input and returns a list of the corresponding circle areas. Try to set it up from scratch and test it.\n", + "Write a function that takes a list `radii` as input and returns a list of the corresponding circle areas. Try to set it up from scratch and test it (note that the build-in `map()` function does the same).\n", "\n", "You can use the function from the previous exercise if you want." ] @@ -866,7 +876,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.7.5-final" }, "latex_envs": { "LaTeX_envs_menu_present": true, @@ -907,4 +917,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} +} \ No newline at end of file From 42ed0e5518ad35f2645a6b6a4e8b897855c3f8e4 Mon Sep 17 00:00:00 2001 From: "Kenneth C. Kleissl" Date: Fri, 10 Jan 2020 11:37:52 +0100 Subject: [PATCH 2/2] fix of invalid notebook --- .../Session 2 - Data Structures.ipynb | 2 +- .../Session 3 - Functions.ipynb | 369 +----------------- .../Session 4 - Plotting.ipynb | 2 +- 3 files changed, 15 insertions(+), 358 deletions(-) diff --git a/Session 2 - Data Structures/Session 2 - Data Structures.ipynb b/Session 2 - Data Structures/Session 2 - Data Structures.ipynb index 4cd910f..fe0a013 100644 --- a/Session 2 - Data Structures/Session 2 - Data Structures.ipynb +++ b/Session 2 - Data Structures/Session 2 - Data Structures.ipynb @@ -1701,7 +1701,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.5" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/Session 3 - Functions/Session 3 - Functions.ipynb b/Session 3 - Functions/Session 3 - Functions.ipynb index ff7a56c..e0675c2 100644 --- a/Session 3 - Functions/Session 3 - Functions.ipynb +++ b/Session 3 - Functions/Session 3 - Functions.ipynb @@ -1,337 +1,5 @@ { "cells": [ - { - "cell_type": "markdown", - "metadata": { - "cell_style": "center" - }, - "source": [ - "\n", - "# 3. Functions\n", - "A **function** is a block of code that is first defined, and thereafter can be called to run as many times as needed. A function might have arguments, some of which can be optional if a default value is specified.\n", - "\n", - "A function is called by parentheses: `function_name()`. Arguments are placed inside the parentehes and comma separated if there are more than one.\n", - "Similar to `f(x, y)` from mathematics.\n", - "\n", - "A function can return one or more values to the caller. The values to return are put in the `return` statement. When the code hits a `return` statement the function terminates. If no `return` statement is given, the function will return `None`.\n", - "\n", - "The general syntax of a function is:\n", - "\n", - "~~~python\n", - "def function_name(arg1, arg2, default_arg1=0, default_arg2=None):\n", - " '''This is the docstring \n", - " \n", - " The docstring explains what the function does, so it is like a multiline comment. It does not have to be here, \n", - " but it is good practice to use them to document the code. They are especially useful for more complicated \n", - " functions, although functions should in general be kept as simple as possible.\n", - " Arguments could be explained together with their types (e.g. strings, lists, dicts etc.).\n", - " '''\n", - " \n", - " # Function code goes here\n", - " \n", - " # Possible 'return' statement terminating the function. If 'return' is not specified, function returns None.\n", - " return return_val1, return_val2\n", - "~~~\n", - "\n", - "If multiple values are to be returned, they can be separated by commas as shown. The returned entity will by default be a `tuple`.\n", - "\n", - "Note that when using default arguments, it is good practice to only use immutable types. An example further below will demonstrate why this is recommended. \n", - "\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Basic functions\n", - "A simple function with one argument is defined below." - ] - }, - { - "cell_type": "code", - "execution_count": 1, - "metadata": {}, - "outputs": [ - { - "data": { - "text/html": [ - "" - ], - "text/plain": [ - "" - ] - }, - "execution_count": 1, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "from IPython.display import HTML\n", - "HTML(''.format(open('../css/cowi.css').read()))" - ] - }, { "cell_type": "markdown", "metadata": { @@ -400,7 +68,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -409,7 +77,7 @@ "36.25" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } @@ -427,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -459,7 +127,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { @@ -494,18 +162,7 @@ }, { "cell_type": "markdown", - "execution_count": 1, "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (, line 3)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m The built-in `enumerate` is useful when you want to loop over an iterable together with the index of each of its elements:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" - ] - } - ], "source": [ "## Examples of built-in functions\n", "### Using `enumerate` for looping in index/value pairs\n", @@ -514,7 +171,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": {}, "outputs": [ { @@ -540,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { @@ -572,7 +229,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -610,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -646,7 +303,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { @@ -676,7 +333,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -916,7 +573,7 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -1189,7 +846,7 @@ "" ] }, - "execution_count": 11, + "execution_count": 12, "metadata": {}, "output_type": "execute_result" } @@ -1217,7 +874,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.5" }, "latex_envs": { "LaTeX_envs_menu_present": true, diff --git a/Session 4 - Plotting/Session 4 - Plotting.ipynb b/Session 4 - Plotting/Session 4 - Plotting.ipynb index 137db26..1dea3cf 100644 --- a/Session 4 - Plotting/Session 4 - Plotting.ipynb +++ b/Session 4 - Plotting/Session 4 - Plotting.ipynb @@ -1106,7 +1106,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.5" }, "latex_envs": { "LaTeX_envs_menu_present": true,