From 878aa856987cf59f9608fbdabe305bfe5f9048cc Mon Sep 17 00:00:00 2001 From: Victor Gerardo Rivera <91023367+VicGerardoPR@users.noreply.github.com> Date: Mon, 2 Dec 2024 11:02:10 -0400 Subject: [PATCH] lab1 lab1 --- your-code/main.ipynb | 208 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 175 insertions(+), 33 deletions(-) diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..d727cb7 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 word in words:\n", + " print(word.upper())" ] }, { @@ -41,11 +59,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], "source": [ - "# your code here" + "# New list\n", + "long_words = [word for word in words if len(word) >= 5]\n", + "\n", + "print(long_words)" ] }, { @@ -57,11 +86,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], "source": [ - "# your code here" + "for word in words:\n", + " if word.lower().startswith(\"t\"):\n", + " print(word)\n", + " break # Stop after finding the first match" ] }, { @@ -80,11 +120,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], "source": [ - "# your code here" + "# Create a list of squares using list comprehension\n", + "squares = [x**2 for x in range(1, 11)]\n", + "\n", + "# Print the list of squares\n", + "print(squares)\n" ] }, { @@ -96,11 +148,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 25, 49, 81]\n" + ] + } + ], "source": [ - "# your code here" + "# Create a list of squares of odd numbers using list comprehension\n", + "odd_squares = [x**2 for x in range(1, 11) if x % 2 != 0]\n", + "\n", + "# Print the list of squares of odd numbers\n", + "print(odd_squares)" ] }, { @@ -112,11 +176,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "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" + "# Create a list of squares of multiples of 8 below 1000\n", + "squares_of_multiples_of_8 = [x**2 for x in range(8, 1000, 8)]\n", + "\n", + "# Print the list\n", + "print(squares_of_multiples_of_8)\n" ] }, { @@ -128,7 +204,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +246,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 5 people.\n" + ] + } + ], "source": [ - "# your code here" + "# Find the number of people in the list\n", + "number_of_people = len(people)\n", + "\n", + "# Print the result\n", + "print(f\"There are {number_of_people} people.\")\n" ] }, { @@ -186,11 +274,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 4 people with kids.\n" + ] + } + ], "source": [ - "# your code here" + "# Count the number of people who have kids\n", + "people_with_kids = sum(1 for person in people if person[\"n_kids\"] > 0)\n", + "\n", + "# Print the result\n", + "print(f\"There are {people_with_kids} people with kids.\")\n" ] }, { @@ -202,11 +302,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total number of kids is 10.\n" + ] + } + ], "source": [ - "# your code here" + "# Calculate the total number of kids\n", + "total_kids = sum(person[\"n_kids\"] for person in people)\n", + "\n", + "# Print the result\n", + "print(f\"The total number of kids is {total_kids}.\")\n" ] }, { @@ -218,12 +330,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'name': 'Juan', 'age': 35, 'n_kids': 2}\n", + "{'name': 'Pepe', 'age': 28, 'n_kids': 0}\n", + "{'name': 'Sonia', 'age': 42, 'n_kids': 2}\n", + "{'name': 'LucĂ­a', 'age': 23, 'n_kids': 3}\n", + "{'name': 'Leo', 'age': 56, 'n_kids': 5}\n" + ] + } + ], "source": [ - "# your code here" + "people_next_year = [\n", + " {\n", + " \"name\": person[\"name\"],\n", + " \"age\": person[\"age\"] + 1, # Increment age by 1 year\n", + " \"n_kids\": person[\"n_kids\"] + (1 if person[\"name\"].endswith(\"a\") else 0) # Add an extra kid if name ends with \"a\"\n", + " }\n", + " for person in people\n", + "]\n", + "\n", + "# Print the updated list\n", + "for person in people_next_year:\n", + " print(person)\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -242,7 +384,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.5" }, "toc": { "base_numbering": 1,