From 5553fade17abba46d8608a0e057f200394ab5c02 Mon Sep 17 00:00:00 2001 From: gail-mar Date: Tue, 16 Sep 2025 18:07:13 +0200 Subject: [PATCH] finsihed task --- .gitignore | 5 -- README.md | 16 ---- your-code/main.ipynb | 194 ++++++++++++++++++++++++++++++++++--------- 3 files changed, 155 insertions(+), 60 deletions(-) delete mode 100644 .gitignore delete mode 100644 README.md diff --git a/.gitignore b/.gitignore deleted file mode 100644 index aafcfe2..0000000 --- a/.gitignore +++ /dev/null @@ -1,5 +0,0 @@ -**/.DS_Store -**/*.ipynb_checkpoints/ -**/__pycache__ -node_modules/ - diff --git a/README.md b/README.md deleted file mode 100644 index b0c84c4..0000000 --- a/README.md +++ /dev/null @@ -1,16 +0,0 @@ -![logo_ironhack_blue 7](https://user-images.githubusercontent.com/23629340/40541063-a07a0a8a-601a-11e8-91b5-2f13e4e6b441.png) - -# Lab | for loops and if conditions - -## Introduction - -`for` loops and `if/else` statements are powerful for controlling the flow of your programs. We will practice them right here! - -## Deliverables - -- `main.ipynb` - -## Submission - -Upon completion, add your deliverables to git. Then commit git and push your branch to the remote. - diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..61ae317 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -25,11 +25,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['PLAY', 'FILLING', 'BAR', 'THEATRE', 'EASYGOING', 'DATE', 'LEAD', 'THAT', 'STORY', 'ISLAND']\n" + ] + } + ], "source": [ - "# your code here" + "uppercase_words = [word.upper() for word in words]\n", + "print(uppercase_words)" ] }, { @@ -41,11 +50,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], "source": [ - "# your code here" + "New_list = []\n", + "for word in words:\n", + " if len(word) >= 5:\n", + " New_list.append(word) \n", + "\n", + "print(New_list) \n" ] }, { @@ -57,11 +79,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], "source": [ - "# your code here" + "for word in words:\n", + " if word[0] == \"t\":\n", + " print(word)\n", + " break" ] }, { @@ -80,11 +113,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], "source": [ - "# your code here" + "square_nums = []\n", + "for num in range(1,11):\n", + " square_num = num**2\n", + " square_nums.append(square_num)\n", + "print(square_nums)\n" ] }, { @@ -96,11 +141,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 25, 49, 81]\n" + ] + } + ], "source": [ - "# your code here" + "odd_square_nums = []\n", + "for square_num in square_nums:\n", + " if square_num % 2 != 0:\n", + " odd_square_nums.append(square_num)\n", + "print(odd_square_nums)" ] }, { @@ -112,11 +169,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "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" + "#multiplies of 8 list\n", + "list_8 = []\n", + "for num in range(1,1001):\n", + " if num % 8 == 0:\n", + " square_num = num**2\n", + " list_8.append(square_num)\n", + "print(list_8)" ] }, { @@ -128,7 +199,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +241,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ - "# your code here" + "print(len(people))" ] }, { @@ -186,11 +265,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Juan\n", + "Sonia\n", + "Lucía\n", + "Leo\n", + "Total with kids: 4\n" + ] + } + ], "source": [ - "# your code here" + "count = 0\n", + "for person in people:\n", + " if person[\"n_kids\"] > 0:\n", + " print(person[\"name\"])\n", + " count += 1\n", + "\n", + "print(f\"Total with kids: {count}\")" ] }, { @@ -202,11 +299,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total number of kids: 10\n" + ] + } + ], "source": [ - "# your code here" + "sum_kids = 0\n", + "for person in people:\n", + " sum_kids += person[\"n_kids\"]\n", + "print(f\"Total number of kids: {sum_kids}\")" ] }, { @@ -218,17 +326,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "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": [ - "# your code here" + "updated_list = [\n", + " { 'name': person['name'], \"n_kids\": person[\"n_kids\"] + 1 if person['name'].endswith('a') else person[\"n_kids\"] }\n", + " for person in people\n", + "]\n", + "\n", + "print(updated_list)" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -242,7 +363,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" }, "toc": { "base_numbering": 1, @@ -285,11 +406,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4,