From a8a8a88d258b16b518c989914f745bcf5a5860bc Mon Sep 17 00:00:00 2001 From: Mariana Donabella Date: Thu, 14 Jan 2021 17:36:06 +0100 Subject: [PATCH] lab done --- your-code/main.ipynb | 197 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 167 insertions(+), 30 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..a04ffbf 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,18 +21,35 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 3, 4, 5]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "# your code here Input: list and lambda expression. Output: the transformed list\n", + "\n", + "my_lst = [1,2,3,4]\n", + "my_lmbda = lambda i: i + 1\n", + "new_list = []\n", + "\n", "def modify_list(lst, lmbda):\n", - " \"\"\"\n", - " Input: list and lambda expression\n", - " Output: the transformed list\n", - " \"\"\"\n", + " for i in lst:\n", + " i = lmbda(i)\n", + " new_list.append(i)\n", + " return new_list\n", + " \n", " \n", - " # your code here\n", - " " + "modify_list(my_lst,my_lmbda) " ] }, { @@ -46,11 +63,11 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "f = lambda c : c + 273" ] }, { @@ -62,11 +79,26 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[285, 296, 311, 218, 297]\n" + ] + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", + "k_temps = []\n", + "\n", + "for c in temps:\n", + " k = f(c)\n", + " k_temps.append(k)\n", + " \n", + "print(k_temps)\n", "\n", "# your code here" ] @@ -82,11 +114,31 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "mod = lambda x,y : 1 if (x%y==0) else 0" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mod(10,3)" ] }, { @@ -100,18 +152,26 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", + " return mod(b,3)\n", + "divisor(9) \n", " \n", - " # your code here" + " # Output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise." ] }, { @@ -123,11 +183,24 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 40, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "def divisible5(a):\n", + " return mod(a,5)\n", + "divisible5(10)" ] }, { @@ -139,18 +212,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -269,7 +364,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.4" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": true, + "sideBar": true, + "skip_h1_title": false, + "title_cell": "Table of Contents", + "title_sidebar": "Contents", + "toc_cell": false, + "toc_position": {}, + "toc_section_display": true, + "toc_window_display": false + }, + "varInspector": { + "cols": { + "lenName": 16, + "lenType": 16, + "lenVar": 40 + }, + "kernels_config": { + "python": { + "delete_cmd_postfix": "", + "delete_cmd_prefix": "del ", + "library": "var_list.py", + "varRefreshCmd": "print(var_dic_list())" + }, + "r": { + "delete_cmd_postfix": ") ", + "delete_cmd_prefix": "rm(", + "library": "var_list.r", + "varRefreshCmd": "cat(var_dic_list()) " + } + }, + "types_to_exclude": [ + "module", + "function", + "builtin_function_or_method", + "instance", + "_Feature" + ], + "window_display": false } }, "nbformat": 4,