diff --git a/your-code/main.ipynb b/your-code/main.ipynb index de27676..6eb7988 100644 --- a/your-code/main.ipynb +++ b/your-code/main.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 164, "metadata": {}, "outputs": [], "source": [ @@ -25,11 +25,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 165, "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", + "\n", + "# I make a for loop, using len and range\n", + "for word in range(len(words)):\n", + "# For each word i use .upper() using the index\n", + " print(words[word].upper())\n" ] }, { @@ -41,11 +63,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 166, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The word filling has 7\n", + "\n", + "appending filling to five_letters\n", + "The word theatre has 7\n", + "\n", + "appending theatre to five_letters\n", + "The word easygoing has 9\n", + "\n", + "appending easygoing to five_letters\n", + "The word story has 5\n", + "\n", + "appending story to five_letters\n", + "The word island has 6\n", + "\n", + "appending island to five_letters\n", + "This is a new list containing only words with 5 or more letters\n", + " ['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "# I create an empty list for later\n", + "five_letters = []\n", + "\n", + "# I iterate the words list\n", + "for letters in words:\n", + "\n", + "# I compare the length of each word, if either word successes the condition or no i display a message\n", + " if len(letters) >= 5:\n", + " print(F\"The word {letters} has {len(letters)}\\n\")\n", + " five_letters.append(letters)\n", + " print(f\"appending {letters} to five_letters\")\n", + " else:\n", + "# If not i just continue\n", + " continue\n", + "# I show the final list with those word that contains 5 or more letters\n", + "print(f\"This is a new list containing only words with 5 or more letters\\n {five_letters}\")" ] }, { @@ -57,11 +120,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 171, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The first word that starts with letter t is theatre\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "# Once again, i iterate the list\n", + "for letter in five_letters:\n", + "\n", + "# For each word, that starts with t, the program displays that output \n", + " if(letter.startswith(\"t\")):\n", + " print(f\"The first word that starts with letter t is {letter}\")\n", + "\n" ] }, { @@ -80,11 +159,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 172, "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", + "\n", + "# I create an empty list\n", + "squared_numbers = []\n", + "\n", + "# I use in range function to go from 1 to 10\n", + "for numbers in range(1,11):\n", + "# Square will calculate the square result of each number, so i can append it to the previous list\n", + " square= numbers**2\n", + " squared_numbers.append(square)\n", + "# Here's the output of the list\n", + "print(squared_numbers)" ] }, { @@ -96,11 +194,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 175, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The final list (squared_numbers) is [1, 9, 25, 49, 81]\n", + "The final list (squared_numbers2) is [1, 9, 25, 49, 81]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "# I create an empty list\n", + "squared_numbers = []\n", + "squared_numbers2 = []\n", + "# First method\n", + "\n", + "# I use in range function to go from 1 to 10, and i use the step to skip numbers\n", + "for numbers in range(1,11,2):\n", + "# Square will calculate the square result of each number, so i can append it to the previous list\n", + " square= numbers**2\n", + " squared_numbers.append(square)\n", + "# Here's the output of the list\n", + "print(f\"The final list (squared_numbers) is {squared_numbers}\")\n", + "\n", + "# Second method\n", + "# I use in range function to go from 1 to 10, and i use the step to skip numbers\n", + "for numbers in range(1,11):\n", + "# Making a conditional to check the opposite, so i check if is not even then, i can continue\n", + " if numbers %2 !=0:\n", + "# Square will calculate the square result of each number, so i can append it to the previous list\n", + " square= numbers**2\n", + " squared_numbers2.append(square)\n", + "# Here's the output of the list\n", + "print(f\"The final list (squared_numbers2) is {squared_numbers2}\")" ] }, { @@ -112,11 +243,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 178, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The final list (multiples_of_eight) is: \n", + " [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" + "# your code here\n", + "\n", + "# I create an empty list\n", + "multiples_of_eight = []\n", + "\n", + "# I use in range function to go from 1 to 1000, \n", + "for numbers in range(1,1001):\n", + "# If the module while dividing by 8 is 0, that number is a multiple of eight\n", + " if numbers %8 ==0:\n", + "# Square will calculate the square result of each number, so i can append it to the previous list\n", + " square= numbers**2 \n", + " multiples_of_eight.append(square)\n", + "# Here's the output of the list\n", + "print(f\"The final list (multiples_of_eight) is: \\n {multiples_of_eight}\")" ] }, { @@ -128,7 +281,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 158, "metadata": {}, "outputs": [], "source": [ @@ -170,11 +323,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 181, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "There are 5 people in total\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "# We can use the len function to know the number of people\n", + "print(f\"There are {len(people)} people in total\")\n" ] }, { @@ -188,9 +352,38 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Juan has 2 kids\n", + "Sonia has 2 kids\n", + "Lucía has 3 kids\n", + "Leo has 5 kids\n", + "\n", + "In total there are 4 people with kids\n" + ] + } + ], "source": [ - "# your code here" + "\n", + "# your code here\n", + "\n", + "# First of all, we declare a variable to count later the people with kids\n", + "people_with_kids = 0\n", + "\n", + "# Now we can iterate the people dictionary\n", + "for kids in people:\n", + "\n", + "# If the key n_kids is greater than 0, that person has kids\n", + " if(kids['n_kids'] > 0):\n", + "# We can increase the counter and display a message of that event\n", + " people_with_kids +=1\n", + " print(f\"{kids['name']} has {kids['n_kids']} kids\")\n", + " \n", + "# Showing the output and the final number of people with kids\n", + "print(f\"\\nIn total there are {people_with_child} people with kids\")" ] }, { @@ -202,11 +395,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 187, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "total childs 2\n", + "============\n", + "============\n", + "total childs 4\n", + "============\n", + "total childs 7\n", + "============\n", + "total childs 12\n", + "============\n", + "There in total 10 kids\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "\n", + "# First of all, we declare a variable to count later the kids\n", + "num_children = 0\n", + "\n", + "# We iterate the dictionary\n", + "for kids in people:\n", + "# If one person has more than 0 kids, we increase the num_children counter\n", + " if(kids['n_kids'] > 0):\n", + " num_children += kids['n_kids']\n", + "# Some message to display the event\n", + " print(\"total childs\", num_children)\n", + " print(\"===\"*4)\n", + " \n", + "# Display the final output\n", + "print(f\"There in total {num_childs} kids\")" ] }, { @@ -218,17 +444,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 197, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original people information: \n", + " ----------------------------\n", + " [{'name': 'Juan', 'age': 35, 'n_kids': 2}, {'name': 'Pepe', 'age': 28, 'n_kids': 0}, {'name': 'Sonia', 'age': 42, 'n_kids': 2}, {'name': 'Lucía', 'age': 23, 'n_kids': 3}, {'name': 'Leo', 'age': 56, 'n_kids': 5}] \n", + "\n", + "In the next year, people would have this information: \n", + " ----------------------------\n", + " [{'name': 'Juan', 'age': 36, 'n_kids': 2}, {'name': 'Pepe', 'age': 29, 'n_kids': 0}, {'name': 'Sonia', 'age': 43, 'n_kids': 3}, {'name': 'Lucía', 'age': 24, 'n_kids': 4}, {'name': 'Leo', 'age': 57, 'n_kids': 5}]\n" + ] + } + ], "source": [ - "# your code here" + "# your code here\n", + "\n", + "# We create an empty list\n", + "people_next_year = []\n", + "\n", + "# Now we iterate the people dictionary\n", + "for person in people:\n", + "# We use a new dictionary with the previuos data\n", + " new_person = dict(person)\n", + "# For each person, we add 1 to the age value\n", + " new_person['age'] += 1\n", + "# If someone's name ends with a, we increase the kids amount by 1\n", + " if new_person['name'].endswith(\"a\"):\n", + " new_person['n_kids'] += 1\n", + "# After that we append these info ont the previous list\n", + " people_next_year.append(new_person)\n", + "# Display the output for comparisong reasons\n", + " \n", + "print(\"Original people information: \\n ----------------------------\\n\",people,\"\\n\")\n", + "\n", + "print(\"In the next year, people would have this information: \\n ----------------------------\\n\",people_next_year)\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -242,7 +502,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.11.9" }, "toc": { "base_numbering": 1, @@ -285,11 +545,6 @@ "_Feature" ], "window_display": false - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } } }, "nbformat": 4,