From cbc9dc9163bab9d87ea5ee665381f8fc1bcd3b27 Mon Sep 17 00:00:00 2001 From: Jose Osorno Date: Sat, 13 Sep 2025 13:41:11 +0200 Subject: [PATCH 1/4] LAB | for loops and if conditions --- your-code/main.ipynb | 203 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 165 insertions(+), 38 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..3ef389e 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,9 +27,28 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "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": [ - "# your code here" + "# your code here\n", + "for x in words:\n", + " print(x.upper()) " ] }, { @@ -41,11 +60,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "new_list = []\n", + "for x in words:\n", + " if len(x) > 4:\n", + " new_list.append(x)\n", + "print(new_list)" ] }, { @@ -57,11 +89,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "for x in words:\n", + " if x.startswith('t'):\n", + " print(x)\n", + " break;" ] }, { @@ -80,11 +124,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "new_list = []\n", + "for i in range(1,11):\n", + " new_list.append(i**2)\n", + "print(new_list)" ] }, { @@ -96,11 +152,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 16, 36, 64, 100]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "new_list = []\n", + "for i in range(2,11,2):\n", + " new_list.append(i**2)\n", + "print(new_list)" ] }, { @@ -112,11 +180,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[64, 256, 576, 1024, 1600, 2304, 3136, 4096, 5184, 6400, 7744, 9216, 10816, 12544, 14400, 16384, 18496, 20736, 23104, 25600, 28224, 30976, 33856, 36864, 40000, 43264, 46656, 50176, 53824, 57600, 61504, 65536, 69696, 73984, 78400, 82944, 87616, 92416, 97344, 102400, 107584, 112896, 118336, 123904, 129600, 135424, 141376, 147456, 153664, 160000, 166464, 173056, 179776, 186624, 193600, 200704, 207936, 215296, 222784, 230400, 238144, 246016, 254016, 262144, 270400, 278784, 287296, 295936, 304704, 313600, 322624, 331776, 341056, 350464, 360000, 369664, 379456, 389376, 399424, 409600, 419904, 430336, 440896, 451584, 462400, 473344, 484416, 495616, 506944, 518400, 529984, 541696, 553536, 565504, 577600, 589824, 602176, 614656, 627264, 640000, 652864, 665856, 678976, 692224, 705600, 719104, 732736, 746496, 760384, 774400, 788544, 802816, 817216, 831744, 846400, 861184, 876096, 891136, 906304, 921600, 937024, 952576, 968256, 984064]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "squares = []\n", + "for i in range(1, 1000):\n", + " if(i%8 == 0):\n", + " squares.append(i**2)\n", + "\n", + "print(squares)\n", + "\n" ] }, { @@ -128,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +253,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "print(len(people))" ] }, { @@ -186,11 +278,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "count = 0\n", + "for person in people:\n", + " if(person['n_kids'] > 0):\n", + " count += 1\n", + "print(count)" ] }, { @@ -202,11 +307,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "count = 0\n", + "for person in people:\n", + " count += person['n_kids']\n", + "print(count)" ] }, { @@ -218,17 +335,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[{'name': 'Juan', 'age': 34, 'n_kids': 2}, {'name': 'Pepe', 'age': 27, 'n_kids': 0}, {'name': 'Sonia', 'age': 41, 'n_kids': 2}, {'name': 'LucĂ­a', 'age': 22, 'n_kids': 3}, {'name': 'Leo', 'age': 55, 'n_kids': 5}]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "new_list = []\n", + "for person in people:\n", + " if person['name'].endswith('a'):\n", + " person['n_kids'] += 1\n", + " new_list.append(person)\n", + "\n", + "print(new_list)\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -242,7 +374,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.7" }, "toc": { "base_numbering": 1, @@ -285,11 +417,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4, From 8534d2deae13b6342c1802757eba1d3153a72075 Mon Sep 17 00:00:00 2001 From: Jose Osorno Date: Sat, 13 Sep 2025 14:08:21 +0200 Subject: [PATCH 2/4] Dictionary copy fix --- your-code/main.ipynb | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 3ef389e..6882474 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -25,7 +25,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 56, "metadata": {}, "outputs": [ { @@ -60,7 +60,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 57, "metadata": {}, "outputs": [ { @@ -89,7 +89,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 58, "metadata": {}, "outputs": [ { @@ -124,7 +124,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 59, "metadata": {}, "outputs": [ { @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 60, "metadata": {}, "outputs": [ { @@ -180,7 +180,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 61, "metadata": {}, "outputs": [ { @@ -211,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 66, "metadata": {}, "outputs": [], "source": [ @@ -253,7 +253,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 67, "metadata": {}, "outputs": [ { @@ -278,7 +278,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 68, "metadata": {}, "outputs": [ { @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -335,7 +335,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 70, "metadata": {}, "outputs": [ { @@ -350,9 +350,10 @@ "# your code here\n", "new_list = []\n", "for person in people:\n", - " if person['name'].endswith('a'):\n", - " person['n_kids'] += 1\n", - " new_list.append(person)\n", + " copy = person.copy()\n", + " if copy['name'].endswith('a'):\n", + " copy['n_kids'] += 1\n", + " new_list.append(copy)\n", "\n", "print(new_list)\n" ] From acd795943afc08de51c3298d244e65538ae8cb45 Mon Sep 17 00:00:00 2001 From: Jose Osorno Date: Sat, 13 Sep 2025 14:23:17 +0200 Subject: [PATCH 3/4] Rewrite exericse (undetected) --- your-code/main.ipynb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 6882474..fb13927 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -124,23 +124,23 @@ }, { "cell_type": "code", - "execution_count": 59, + "execution_count": 75, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + "List containing the square of every number: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" ] } ], "source": [ "# your code here\n", - "new_list = []\n", + "n_list = []\n", "for i in range(1,11):\n", - " new_list.append(i**2)\n", - "print(new_list)" + " n_list.append(i**2)\n", + "print(f\"List containing the square of every number: {n_list}\")" ] }, { @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 60, + "execution_count": 72, "metadata": {}, "outputs": [ { @@ -180,7 +180,7 @@ }, { "cell_type": "code", - "execution_count": 61, + "execution_count": 73, "metadata": {}, "outputs": [ { From 00cd703e7ee0a4ef444b8a61da6491416da9ca44 Mon Sep 17 00:00:00 2001 From: Jose Osorno Date: Sat, 13 Sep 2025 14:26:39 +0200 Subject: [PATCH 4/4] English fail, odd is "impar" and even is "par". Lesson learned. --- your-code/main.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index fb13927..e5191fe 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -152,21 +152,21 @@ }, { "cell_type": "code", - "execution_count": 72, + "execution_count": 78, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "[4, 16, 36, 64, 100]\n" + "[1, 9, 25, 49, 81]\n" ] } ], "source": [ "# your code here\n", "new_list = []\n", - "for i in range(2,11,2):\n", + "for i in range(1,11,2):\n", " new_list.append(i**2)\n", "print(new_list)" ]