From 1cd01d89ab94b84c5a488369441d26d0f46b5006 Mon Sep 17 00:00:00 2001 From: Laura Date: Sat, 13 Sep 2025 14:11:18 +0200 Subject: [PATCH 1/3] solve labs --- your-code/main.ipynb | 205 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 166 insertions(+), 39 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..9c7c349 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": [ @@ -25,11 +25,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "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" + "for w in words:\n", + " print(w.upper())" ] }, { @@ -41,11 +59,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['play', 'bar', 'date', 'lead', 'that', 'story']\n" + ] + } + ], "source": [ - "# your code here" + "short_words = [w for w in words if len(w) <= 5]\n", + "print(short_words)" ] }, { @@ -57,11 +84,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], "source": [ - "# your code here" + "for w in words:\n", + " if w[0] == \"t\":\n", + " print(w)\n", + " break" ] }, { @@ -80,11 +118,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], "source": [ - "# your code here" + "squares = [i**2 for i in range(1,11)]\n", + "print(squares)" ] }, { @@ -96,11 +143,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "9\n", + "25\n", + "49\n", + "81\n" + ] + } + ], "source": [ - "# your code here" + "for i in range(1, 11):\n", + " if i%2 != 0:\n", + " print(i**2)" ] }, { @@ -112,11 +173,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "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, 1000000]\n" + ] + } + ], "source": [ - "# your code here" + "square8 = []\n", + "num = 0\n", + "\n", + "while num < 1000:\n", + " num += 8\n", + " square8.append(num**2)\n", + "\n", + "print(square8)\n", + "\n" ] }, { @@ -128,7 +205,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +247,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 5 people.\n" + ] + } + ], "source": [ - "# your code here" + "print(f\"There are {len(people)} people.\")" ] }, { @@ -186,11 +271,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 people have kids.\n" + ] + } + ], "source": [ - "# your code here" + "with_kids = 0\n", + "\n", + "for p in people:\n", + " if p[\"n_kids\"] > 0:\n", + " with_kids += 1\n", + "\n", + "print(f\"{with_kids} people have kids.\")" ] }, { @@ -202,11 +301,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are a total of 10 kids.\n" + ] + } + ], "source": [ - "# your code here" + "kids = 0\n", + "\n", + "for p in people:\n", + " kids += p[\"n_kids\"]\n", + "\n", + "print(f\"There are a total of {kids} kids.\")" ] }, { @@ -218,17 +330,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "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" + "people_next_year = []\n", + "\n", + "for p in people:\n", + " new_person = p\n", + " \n", + " if p[\"name\"][-1] == \"a\":\n", + " new_person[\"n_kids\"] += 1\n", + "\n", + " \n", + " people_next_year.append(new_person)\n", + "\n", + "print(people_next_year)\n", + " " ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -242,7 +374,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" }, "toc": { "base_numbering": 1, @@ -285,11 +417,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4, From db003becdb515f7933cd0e9a7f341e0daca97686 Mon Sep 17 00:00:00 2001 From: Laura Date: Sat, 13 Sep 2025 14:14:56 +0200 Subject: [PATCH 2/3] fix silly mistakes --- your-code/main.ipynb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index 9c7c349..4624aed 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -59,19 +59,19 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 25, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['play', 'bar', 'date', 'lead', 'that', 'story']\n" + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" ] } ], "source": [ - "short_words = [w for w in words if len(w) <= 5]\n", + "short_words = [w for w in words if len(w) >= 5]\n", "print(short_words)" ] }, @@ -143,25 +143,24 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 26, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "1\n", - "9\n", - "25\n", - "49\n", - "81\n" + "[1, 9, 25, 49, 81]\n" ] } ], "source": [ + "sqr = []\n", "for i in range(1, 11):\n", " if i%2 != 0:\n", - " print(i**2)" + " sqr.append(i**2)\n", + "\n", + "print(sqr)" ] }, { From f590dfa20831f4374ee3cd3b75dcff0b401553aa Mon Sep 17 00:00:00 2001 From: Laura Date: Sat, 13 Sep 2025 14:16:52 +0200 Subject: [PATCH 3/3] copy dict by value instead of referencing the old one --- 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 4624aed..abfc627 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -204,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 27, "metadata": {}, "outputs": [], "source": [ @@ -329,7 +329,7 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 28, "metadata": {}, "outputs": [ { @@ -344,7 +344,7 @@ "people_next_year = []\n", "\n", "for p in people:\n", - " new_person = p\n", + " new_person = p.copy()\n", " \n", " if p[\"name\"][-1] == \"a\":\n", " new_person[\"n_kids\"] += 1\n",