diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 01257d4..9fe1f60 100755 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -21,18 +21,49 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + }, + { + "data": { + "text/plain": [ + "[2, 3, 4]" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ + "\n", "def modify_list(lst, lmbda):\n", " \"\"\"\n", " Input: list and lambda expression\n", " Output: the transformed list\n", " \"\"\"\n", - " \n", " # your code here\n", - " " + " #use map\n", + " x=list(map(lmbda,lst))\n", + " return x\n", + "\n", + "num=[4]\n", + "\n", + "lmbda_1=(lambda n:n+1) \n", + "print(lmbda(4)) \n", + "lst_1=[1,2,3]\n", + "\n", + "\n", + "list(map((lambda n:n+1),lst))\n", + "\n", + "#modify_list(lmbda_1,lst_1)" ] }, { @@ -46,11 +77,25 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "303.15" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "temp=(30)\n", + "f=(lambda x: x +273.15)\n", + "f(temp)\n" ] }, { @@ -62,13 +107,26 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", "\n", - "# your code here" + "# your code here\n", + "\n", + "list(map(lambda x: x + 273.15, temps))" ] }, { @@ -82,11 +140,49 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# your code here" + "# your code here\n", + "# lambda : if else \n", + "\n", + "#lambda x : True if (x > 10 and x < 20) else False\n", + "\n", + "mod = lambda x, y: 1 if x%y == 0 else 0\n", + "\n", + "mod(2,1)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mod(8,5)\n" ] }, { @@ -100,7 +196,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ @@ -111,7 +207,10 @@ " divisible by another number (to be passed later) and zero otherwise.\n", " \"\"\"\n", " \n", - " # your code here" + " # your code here\n", + "\n", + " mod = lambda b, x: 1 if b%x == 0 else 0\n", + " return mod\n" ] }, { @@ -123,11 +222,12 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ - "# your code here" + "# your code here\n", + "divisible5=divisor(5)" ] }, { @@ -139,9 +239,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "() missing 1 required positional argument: 'y'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdivisible5\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;31mTypeError\u001b[0m: () missing 1 required positional argument: 'y'" + ] + } + ], "source": [ "divisible5(10)" ] @@ -269,7 +381,49 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.8.5" + }, + "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,