diff --git a/your-code/main.ipynb b/your-code/main.ipynb deleted file mode 100644 index de27676..0000000 --- a/your-code/main.ipynb +++ /dev/null @@ -1,297 +0,0 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Words" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "words = ['play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Print every word in upper case**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Create a new list containing only words with 5 or more letters**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Print the first word starting with \"t\"**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Numbers" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Create a list containing the square of every number from 1 to 10**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Print a list containing the square of every odd number from 1 to 10**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**Create a list with the squares of all multiples of 8 below 1000**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## People" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "people = [\n", - " {\n", - " \"name\": \"Juan\",\n", - " \"age\": 34,\n", - " \"n_kids\": 2\n", - " },\n", - " {\n", - " \"name\": \"Pepe\",\n", - " \"age\": 27,\n", - " \"n_kids\": 0\n", - " },\n", - " {\n", - " \"name\": \"Sonia\",\n", - " \"age\": 41,\n", - " \"n_kids\": 1\n", - " },\n", - " {\n", - " \"name\": \"Lucía\",\n", - " \"age\": 22,\n", - " \"n_kids\": 2\n", - " },\n", - " {\n", - " \"name\": \"Leo\",\n", - " \"age\": 55,\n", - " \"n_kids\": 5\n", - " }\n", - "]" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**How many people are there?**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**How many people have kids**?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**How many kids do they have in total?**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "**In a year's time, names ending with \"a\" will have an extra kid. Create a list of dictionaries with people's info in a year's time**" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# your code here" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "toc": { - "base_numbering": 1, - "nav_menu": {}, - "number_sections": false, - "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": true - }, - "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 - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } - } - }, - "nbformat": 4, - "nbformat_minor": 4 -} diff --git a/your-code/main2.ipynb b/your-code/main2.ipynb new file mode 100644 index 0000000..5b09e4a --- /dev/null +++ b/your-code/main2.ipynb @@ -0,0 +1,393 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Words" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "words = ['play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print every word in upper case**" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PLAY\n", + "FILLING\n", + "BAR\n", + "THEATRE\n", + "EASYGOING\n", + "DATE\n", + "LEAD\n", + "THAT\n", + "STORY\n", + "ISLAND\n" + ] + } + ], + "source": [ + "for word in words:\n", + " print(word.upper())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a new list containing only words with 5 or more letters**" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], + "source": [ + "long_words = [word for word in words if len(word) >= 5]\n", + "\n", + "print(long_words)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print the first word starting with \"t\"**" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], + "source": [ + "for word in words:\n", + " if word.startswith(\"t\"):\n", + " print(word)\n", + " break" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Numbers" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a list containing the square of every number from 1 to 10**" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], + "source": [ + "squares = [n**2 for n in range(1,11)]\n", + "print(squares)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Print a list containing the square of every odd number from 1 to 10**" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 25, 49, 81]\n" + ] + } + ], + "source": [ + "odd_squares = [n**2 for n in range(1, 11) if n % 2 != 0]\n", + "print(odd_squares)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Create a list with the squares of all multiples of 8 below 1000**" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[16, 64, 144, 256, 400, 576, 784, 1024, 1296, 1600, 1936, 2304, 2704, 3136, 3600, 4096, 4624, 5184, 5776, 6400, 7056, 7744, 8464, 9216, 10000, 10816, 11664, 12544, 13456, 14400, 15376, 16384, 17424, 18496, 19600, 20736, 21904, 23104, 24336, 25600, 26896, 28224, 29584, 30976, 32400, 33856, 35344, 36864, 38416, 40000, 41616, 43264, 44944, 46656, 48400, 50176, 51984, 53824, 55696, 57600, 59536, 61504, 63504, 65536, 67600, 69696, 71824, 73984, 76176, 78400, 80656, 82944, 85264, 87616, 90000, 92416, 94864, 97344, 99856, 102400, 104976, 107584, 110224, 112896, 115600, 118336, 121104, 123904, 126736, 129600, 132496, 135424, 138384, 141376, 144400, 147456, 150544, 153664, 156816, 160000, 163216, 166464, 169744, 173056, 176400, 179776, 183184, 186624, 190096, 193600, 197136, 200704, 204304, 207936, 211600, 215296, 219024, 222784, 226576, 230400, 234256, 238144, 242064, 246016, 250000, 254016, 258064, 262144, 266256, 270400, 274576, 278784, 283024, 287296, 291600, 295936, 300304, 304704, 309136, 313600, 318096, 322624, 327184, 331776, 336400, 341056, 345744, 350464, 355216, 360000, 364816, 369664, 374544, 379456, 384400, 389376, 394384, 399424, 404496, 409600, 414736, 419904, 425104, 430336, 435600, 440896, 446224, 451584, 456976, 462400, 467856, 473344, 478864, 484416, 490000, 495616, 501264, 506944, 512656, 518400, 524176, 529984, 535824, 541696, 547600, 553536, 559504, 565504, 571536, 577600, 583696, 589824, 595984, 602176, 608400, 614656, 620944, 627264, 633616, 640000, 646416, 652864, 659344, 665856, 672400, 678976, 685584, 692224, 698896, 705600, 712336, 719104, 725904, 732736, 739600, 746496, 753424, 760384, 767376, 774400, 781456, 788544, 795664, 802816, 810000, 817216, 824464, 831744, 839056, 846400, 853776, 861184, 868624, 876096, 883600, 891136, 898704, 906304, 913936, 921600, 929296, 937024, 944784, 952576, 960400, 968256, 976144, 984064, 992016]\n" + ] + } + ], + "source": [ + "squares_div_by_8 = [n**2 for n in range(1, 1000) if (n**2) % 8 == 0]\n", + "print(squares_div_by_8)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## People" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "people = [\n", + " {\n", + " \"name\": \"Juan\",\n", + " \"age\": 34,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Pepe\",\n", + " \"age\": 27,\n", + " \"n_kids\": 0\n", + " },\n", + " {\n", + " \"name\": \"Sonia\",\n", + " \"age\": 41,\n", + " \"n_kids\": 1\n", + " },\n", + " {\n", + " \"name\": \"Lucía\",\n", + " \"age\": 22,\n", + " \"n_kids\": 2\n", + " },\n", + " {\n", + " \"name\": \"Leo\",\n", + " \"age\": 55,\n", + " \"n_kids\": 5\n", + " }\n", + "]" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many people are there?**" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "print(len(people))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many people have kids**?" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "people_with_kids = sum(1 for person in people if person[\"n_kids\"] > 0)\n", + "print(people_with_kids)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**How many kids do they have in total?**" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], + "source": [ + "total_kids = sum(person[\"n_kids\"] for person in people)\n", + "print(total_kids)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**In a year's time, names ending with \"a\" will have an extra kid. Create a list of dictionaries with people's info in a year's time**" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'name': 'Juan', 'n_kids': 2}, {'name': 'Pepe', 'n_kids': 0}, {'name': 'Sonia', 'n_kids': 2}, {'name': 'Lucía', 'n_kids': 3}, {'name': 'Leo', 'n_kids': 5}]\n" + ] + } + ], + "source": [ + "kids_future = [{\"name\": person[\"name\"], \"n_kids\": person[\"n_kids\"] + (1 if person[\"name\"].endswith(\"a\") else 0)} for person in people]\n", + "print(kids_future)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "base", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + }, + "toc": { + "base_numbering": 1, + "nav_menu": {}, + "number_sections": false, + "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": true + }, + "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, + "nbformat_minor": 4 +}