From 1286163f70074e71871ec2c43221b6a8a2ae302b Mon Sep 17 00:00:00 2001 From: MiguelSM91 Date: Tue, 27 Oct 2020 14:04:38 +0100 Subject: [PATCH] solved lab --- your-code/main.ipynb | 95 +++++++++++++++++++++++++++++++------------- 1 file changed, 68 insertions(+), 27 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..f110cbb 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,7 +21,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -30,8 +30,12 @@ " Input: list and lambda expression\n", " Output: the transformed list\n", " \"\"\"\n", - " \n", - " # your code here\n", + " new_list=[]\n", + " for element in lst:\n", + " y = lmbda(element)\n", + " new_list.append(y)\n", + " \n", + " print(new_list)\n", " " ] }, @@ -46,11 +50,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "kelvin = lambda element: element + 273.15" ] }, { @@ -62,13 +66,28 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ - "temps = [12, 23, 38, -55, 24]\n", - "\n", - "# your code here" + "temps = [12, 23, 38, -55, 24]" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n" + ] + } + ], + "source": [ + "modify_list(temps, kelvin)" ] }, { @@ -82,11 +101,11 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "mod = lambda x,y: 1 if x % y == 0 else 0" ] }, { @@ -100,18 +119,18 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ - "def divisor(b):\n", - " \"\"\"\n", - " Input: a number\n", - " Output: a function that returns 1 if the number is \n", - " divisible by another number (to be passed later) and zero otherwise.\n", - " \"\"\"\n", - " \n", - " # your code here" + "#def divisor(b):\n", + " # \"\"\"\n", + " # Input: a number\n", + " # Output: a function that returns 1 if the number is \n", + " # divisible by another number (to be passed later) and zero otherwise.\n", + " # \"\"\"\n", + "def divisible(x):\n", + " return lambda y: 1 if y % x == 0 else 0" ] }, { @@ -123,11 +142,11 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 28, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "divisible5= divisible(5)" ] }, { @@ -139,18 +158,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -269,7 +310,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" } }, "nbformat": 4,