diff --git a/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb new file mode 100644 index 0000000..bdc8159 --- /dev/null +++ b/.ipynb_checkpoints/lab-python-data-structures-checkpoint.ipynb @@ -0,0 +1,477 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab | Data Structures " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 1: Working with Lists" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you are building a program for a teacher who wants to track the progress of their students throughout the semester. The teacher wants to input the grades of each student one by one, and get a summary of their performance. There are in total 5 students. You are tasked with building the program that will allow the teacher to do this easily.\n", + "\n", + "The program will prompt the teacher to enter the grades of each student. Once the teacher has entered all the grades, the program will calculate the total sum of the grades and display it on the screen. Then, the program will create a new list by selecting only the grades of the first, third, and fifth students entered by the teacher, and sort them in ascending order.\n", + "\n", + "Finally, the program will print out the new list, along with its length and the number of occurrences of the score 5 in the list. This will give the teacher a good overview of the performance of the selected students, and help them identify any potential issues early on." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint:*\n", + "- You can use the input() function to ask the user to enter their information.\n", + "- Look for list methods to perform the tasks. \n", + "- Remember, it is possible to get a part of the sequence using:\n", + "\n", + " ```python\n", + " sequence[x:y:z]\n", + " ```\n", + " where x, y, z are integers.\n", + "\n", + " The above returns a new sequence with the following characteristics:\n", + "\n", + " - A sequence with the same type as the original (a slice of a list is a list, a slice of a tuple is a tuple, and a slice of a string is a string).\n", + " - A sequence with elements from `sequence [x]` to `sequence [y-1]` (does not include a sequence [y]). By skipping `z` elements each time, it can be omitted if ` z = 1`.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources:*\n", + "- *[Python Lists](https://www.w3schools.com/python/python_lists.asp)*\n", + "- *[Python List Methods](https://www.w3schools.com/python/python_ref_list.asp)*\n", + "- *[Python Built-in Functions](https://docs.python.org/3/library/functions.html)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter grade for student 1: 15\n", + "Enter grade for student 2: 20\n", + "Enter grade for student 3: 18\n", + "Enter grade for student 4: 15\n", + "Enter grade for student 5: 20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total sum of grades is: 88\n", + "New list: [15, 18, 20]\n", + "Length of the new list: 3\n", + "Number of times 5 appears: 0\n" + ] + } + ], + "source": [ + "# 1 Create an empty list for grades\n", + "\n", + "grades = []\n", + "\n", + "# 2 Ask for grade of 5 students\n", + "for i in range(5):\n", + " grade = int(input(f\"Enter grade for student {i + 1}: \"))\n", + " grades.append(grade)\n", + "\n", + "# 3 Sum total grades\n", + "total = sum(grades)\n", + "print(\"The total sum of grades is:\", total)\n", + "\n", + "# 4 Create a list with the first, third and 5th student\n", + "selected = [grades[0], grades[2], grades[4]]\n", + "\n", + "#5 Order the list ascendent order\n", + "selected.sort()\n", + "\n", + "#Print results\n", + "print(\"New list:\", selected)\n", + "print(\"Length of the new list:\", len(selected))\n", + "print(\"Number of times 5 appears:\", selected.count(5))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 2: Tuples" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you're running a fruit stand and want to keep track of your inventory. Write a Python program that does the following:\n", + "\n", + "- Initializes a tuple with 5 different types of fruit.\n", + "- Outputs the first and last elements of the tuple, so you can see the full range of fruits the store offers.\n", + "- Replaces the second element of the tuple with a new fruit that the store has recently received, and prints the updated tuple so you can see the changes.\n", + "- Concatenates a new tuple containing 2 additional fruits to the original tuple, so you can add them to the store inventory, and prints the resulting tuple to see the updated inventory.\n", + "- Splits the resulting tuple into 2 tuples of 3 elements each (the first tuple contains the first 3 elements, and the second tuple contains the last 3 elements), so you can organize the inventory more effectively.\n", + "- Combines the 2 tuples from the previous step with the original tuple into a new tuple, and prints the resulting tuple and its length, so you can see the final inventory after all the changes." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Tuples Examples and Methods](https://www.w3schools.com/python/python_tuples.asp)*\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original tuple: ('apple', 'banana', 'orange', 'grape', 'pear')\n", + "First fruit: apple\n", + "Last fruit: pear\n", + "Updated tuple: ('apple', 'mango', 'orange', 'grape', 'pear')\n", + "Tuple after adding 2 fruits: ('apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'pineapple')\n", + "First tuple (3 elements): ('apple', 'mango', 'orange')\n", + "Second tuple (3 elements): ('grape', 'pear', 'kiwi')\n", + "Final tuple: ('apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'pineapple')\n", + "Lenght of final tuple: 13\n" + ] + } + ], + "source": [ + "# Step 1: Initialize a tuple with 5 fruits\n", + "fruits = (\"apple\", \"banana\", \"orange\", \"grape\", \"pear\")\n", + "print(\"Original tuple:\", fruits)\n", + "\n", + "# Step 2: print the first and last elements\n", + "print(\"First fruit:\", fruits[0])\n", + "print(\"Last fruit:\", fruits[-1])\n", + "\n", + "# Step 3: replace the second element\n", + "fruits_list = list(fruits)\n", + "fruits_list[1] = \"mango\"\n", + "fruits = tuple(fruits_list)\n", + "print(\"Updated tuple:\", fruits)\n", + "\n", + "# Step 4: Concatenate 2 additional fruits\n", + "extra_fruits = (\"kiwi\", \"pineapple\")\n", + "fruits = fruits + extra_fruits\n", + "print(\"Tuple after adding 2 fruits:\", fruits)\n", + "\n", + "# Step 5: Split into 2 tuples of 3 elements each \n", + "tuple1 = fruits[:3]\n", + "tuple2 = fruits[3:6]\n", + "print(\"First tuple (3 elements):\", tuple1)\n", + "print(\"Second tuple (3 elements):\", tuple2)\n", + "\n", + "#Step 5: Combine with the original tuple and show final result\n", + "final_tuple = tuple1 + tuple2 + fruits\n", + "print(\"Final tuple:\", final_tuple)\n", + "print(\"Lenght of final tuple:\", len(final_tuple))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 3: Sets" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Imagine you are a data analyst working for a literature museum. Your manager has given you two poems to analyze, and she wants you to write a Python program to extract useful information from them.\n", + "\n", + "Your program should:\n", + "\n", + "- Create two sets, one for each poem, containing all unique words in both poems (ignoring case and punctuation).\n", + "- Print the number of unique words in each set.\n", + "- Identify and print the unique words present in the first poem but not in the second one.\n", + "- Identify and print the unique words present in the second poem but not in the first one.\n", + "- Identify and print the unique words present in both poems and print it in alphabetical order." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources:*\n", + "- *[Python Sets](https://www.w3schools.com/python/python_sets.asp)* \n", + "- *[Python Set Methods](https://www.w3schools.com/python/python_ref_set.asp)*\n", + "- *[Python String Methods](https://www.w3schools.com/python/python_ref_string.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "poem = \"\"\"Some say the world will end in fire,\n", + "Some say in ice.\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire.\n", + "But if it had to perish twice,\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice.\"\"\"\n", + "\n", + "new_poem = \"\"\"Some say life is but a dream,\n", + "Some say it's a test.\n", + "From what I've seen and what I deem,\n", + "I side with those who see it as a quest.\n", + "\n", + "But if it had to end today,\n", + "I think I know enough of love,\n", + "To say that though it fades away,\n", + "It's still what we are made of.\"\"\"" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Unique words in first poem: 41\n", + "Unique words in second poem: 42\n", + "\n", + "Words only in first poem: {'hate', 'fire', 'suffice', 'great', 'for', 'twice', 'destruction', 'would', 'world', 'will', 'ice', 'hold', 'tasted', 'favor', 'desire', 'also', 'perish', 'i’ve', 'in', 'the'}\n", + "\n", + "Words only in second poem: {'are', 'seen', 'a', 'made', 'we', 'life', 'see', 'dream', 'as', 'love', 'fades', 'quest', 'ive', 'side', 'test', 'still', 'though', 'deem', 'away', 'its', 'today'}\n", + "\n", + "Words in both poems (alphabetical): ['and', 'but', 'end', 'enough', 'from', 'had', 'i', 'if', 'is', 'it', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n" + ] + } + ], + "source": [ + "# --- SINGLE, CLEAN CELL ---\n", + "import builtins, string # builtins nos da la len() original pase lo que pase\n", + "\n", + "poem = \"\"\"Some say the world will end in fire,\n", + "Some say in ice.\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire.\n", + "But if it had to perish twice,\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice.\"\"\"\n", + "\n", + "new_poem = \"\"\"Some say life is but a dream,\n", + "Some say it's a test.\n", + "From what I've seen and what I deem,\n", + "I side with those who see it as a quest.\n", + "\n", + "But if it had to end today,\n", + "I think I know enough of love,\n", + "To say that though it fades away,\n", + "It's still what we are made of.\"\"\"\n", + "\n", + "def clean_text(text: str):\n", + " text = text.lower()\n", + " for p in string.punctuation:\n", + " text = text.replace(p, \"\")\n", + " return text.split()\n", + "\n", + "set1 = set(clean_text(poem))\n", + "set2 = set(clean_text(new_poem))\n", + "\n", + "# Usamos la len ORIGINAL explícitamente: builtins.len(...)\n", + "print(\"Unique words in first poem:\", builtins.len(set1))\n", + "print(\"Unique words in second poem:\", builtins.len(set2))\n", + "\n", + "print(\"\\nWords only in first poem:\", set1 - set2)\n", + "print(\"\\nWords only in second poem:\", set2 - set1)\n", + "print(\"\\nWords in both poems (alphabetical):\", sorted(set1 & set2))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise 4: Dictionaries" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Consider the following dictionary of students with their scores in different subjects. One of the students, Bob, has complained about his score in Philosophy and, after reviewing it, the teacher has decided to update his score to 100. Write a Python program that updates Bob's score in Philosophy to 100 in the dictionary." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Dictionary Examples and Methods](https://www.w3schools.com/python/python_dictionaries.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "grades = {'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}}" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n" + ] + } + ], + "source": [ + "grades = {'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90},'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}}\n", + "\n", + "grades ['Bob']['Philosophy'] = 100\n", + "print (grades)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Bonus" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Below are the two lists. Write a Python program to convert them into a dictionary in a way that item from list1 is the key and item from list2 is the value." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint: Use the zip() function. This function takes two or more iterables (like list, dict, string), aggregates them in a tuple, and returns it. Afterwards, you can use a function that turns a tuple into a dictionary.*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Recommended External Resources: [Python Zip Function](https://www.w3schools.com/python/ref_func_zip.asp)*\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}\n" + ] + } + ], + "source": [ + "keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n", + "values = [75, 85, 60,90]\n", + "\n", + "grades_dict = dict(zip(keys, values))\n", + "print(grades_dict)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Get the subject with the minimum score from the previous dictionary." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Hint: Use the built-in function min(). Read about the parameter key.*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "*Recommended External Resources:*\n", + "- *[Python Min Function Official Documentation](https://docs.python.org/3.8/library/functions.html#min)*\n", + "- *[How to use key function in max and min in Python](https://medium.com/analytics-vidhya/how-to-use-key-function-in-max-and-min-in-python-1fdbd661c59c)*" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chemistry\n" + ] + } + ], + "source": [ + "lowest_subject = min(grades_dict, key=grades_dict.get)\n", + "print(lowest_subject)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.5" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8ba652c..bdc8159 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,11 +57,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter grade for student 1: 15\n", + "Enter grade for student 2: 20\n", + "Enter grade for student 3: 18\n", + "Enter grade for student 4: 15\n", + "Enter grade for student 5: 20\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The total sum of grades is: 88\n", + "New list: [15, 18, 20]\n", + "Length of the new list: 3\n", + "Number of times 5 appears: 0\n" + ] + } + ], "source": [ - "# Your code here" + "# 1 Create an empty list for grades\n", + "\n", + "grades = []\n", + "\n", + "# 2 Ask for grade of 5 students\n", + "for i in range(5):\n", + " grade = int(input(f\"Enter grade for student {i + 1}: \"))\n", + " grades.append(grade)\n", + "\n", + "# 3 Sum total grades\n", + "total = sum(grades)\n", + "print(\"The total sum of grades is:\", total)\n", + "\n", + "# 4 Create a list with the first, third and 5th student\n", + "selected = [grades[0], grades[2], grades[4]]\n", + "\n", + "#5 Order the list ascendent order\n", + "selected.sort()\n", + "\n", + "#Print results\n", + "print(\"New list:\", selected)\n", + "print(\"Length of the new list:\", len(selected))\n", + "print(\"Number of times 5 appears:\", selected.count(5))\n" ] }, { @@ -95,11 +139,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original tuple: ('apple', 'banana', 'orange', 'grape', 'pear')\n", + "First fruit: apple\n", + "Last fruit: pear\n", + "Updated tuple: ('apple', 'mango', 'orange', 'grape', 'pear')\n", + "Tuple after adding 2 fruits: ('apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'pineapple')\n", + "First tuple (3 elements): ('apple', 'mango', 'orange')\n", + "Second tuple (3 elements): ('grape', 'pear', 'kiwi')\n", + "Final tuple: ('apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'apple', 'mango', 'orange', 'grape', 'pear', 'kiwi', 'pineapple')\n", + "Lenght of final tuple: 13\n" + ] + } + ], "source": [ - "# Your code here" + "# Step 1: Initialize a tuple with 5 fruits\n", + "fruits = (\"apple\", \"banana\", \"orange\", \"grape\", \"pear\")\n", + "print(\"Original tuple:\", fruits)\n", + "\n", + "# Step 2: print the first and last elements\n", + "print(\"First fruit:\", fruits[0])\n", + "print(\"Last fruit:\", fruits[-1])\n", + "\n", + "# Step 3: replace the second element\n", + "fruits_list = list(fruits)\n", + "fruits_list[1] = \"mango\"\n", + "fruits = tuple(fruits_list)\n", + "print(\"Updated tuple:\", fruits)\n", + "\n", + "# Step 4: Concatenate 2 additional fruits\n", + "extra_fruits = (\"kiwi\", \"pineapple\")\n", + "fruits = fruits + extra_fruits\n", + "print(\"Tuple after adding 2 fruits:\", fruits)\n", + "\n", + "# Step 5: Split into 2 tuples of 3 elements each \n", + "tuple1 = fruits[:3]\n", + "tuple2 = fruits[3:6]\n", + "print(\"First tuple (3 elements):\", tuple1)\n", + "print(\"Second tuple (3 elements):\", tuple2)\n", + "\n", + "#Step 5: Combine with the original tuple and show final result\n", + "final_tuple = tuple1 + tuple2 + fruits\n", + "print(\"Final tuple:\", final_tuple)\n", + "print(\"Lenght of final tuple:\", len(final_tuple))\n" ] }, { @@ -136,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -163,11 +251,64 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Unique words in first poem: 41\n", + "Unique words in second poem: 42\n", + "\n", + "Words only in first poem: {'hate', 'fire', 'suffice', 'great', 'for', 'twice', 'destruction', 'would', 'world', 'will', 'ice', 'hold', 'tasted', 'favor', 'desire', 'also', 'perish', 'i’ve', 'in', 'the'}\n", + "\n", + "Words only in second poem: {'are', 'seen', 'a', 'made', 'we', 'life', 'see', 'dream', 'as', 'love', 'fades', 'quest', 'ive', 'side', 'test', 'still', 'though', 'deem', 'away', 'its', 'today'}\n", + "\n", + "Words in both poems (alphabetical): ['and', 'but', 'end', 'enough', 'from', 'had', 'i', 'if', 'is', 'it', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n" + ] + } + ], "source": [ - "# Your code here" + "# --- SINGLE, CLEAN CELL ---\n", + "import builtins, string # builtins nos da la len() original pase lo que pase\n", + "\n", + "poem = \"\"\"Some say the world will end in fire,\n", + "Some say in ice.\n", + "From what I’ve tasted of desire\n", + "I hold with those who favor fire.\n", + "But if it had to perish twice,\n", + "I think I know enough of hate\n", + "To say that for destruction ice\n", + "Is also great\n", + "And would suffice.\"\"\"\n", + "\n", + "new_poem = \"\"\"Some say life is but a dream,\n", + "Some say it's a test.\n", + "From what I've seen and what I deem,\n", + "I side with those who see it as a quest.\n", + "\n", + "But if it had to end today,\n", + "I think I know enough of love,\n", + "To say that though it fades away,\n", + "It's still what we are made of.\"\"\"\n", + "\n", + "def clean_text(text: str):\n", + " text = text.lower()\n", + " for p in string.punctuation:\n", + " text = text.replace(p, \"\")\n", + " return text.split()\n", + "\n", + "set1 = set(clean_text(poem))\n", + "set2 = set(clean_text(new_poem))\n", + "\n", + "# Usamos la len ORIGINAL explícitamente: builtins.len(...)\n", + "print(\"Unique words in first poem:\", builtins.len(set1))\n", + "print(\"Unique words in second poem:\", builtins.len(set2))\n", + "\n", + "print(\"\\nWords only in first poem:\", set1 - set2)\n", + "print(\"\\nWords only in second poem:\", set2 - set1)\n", + "print(\"\\nWords in both poems (alphabetical):\", sorted(set1 & set2))\n" ] }, { @@ -193,7 +334,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -202,11 +343,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}, 'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 100}}\n" + ] + } + ], "source": [ - "# Your code here" + "grades = {'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90},'Bob': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}}\n", + "\n", + "grades ['Bob']['Philosophy'] = 100\n", + "print (grades)" ] }, { @@ -239,14 +391,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}\n" + ] + } + ], "source": [ "keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n", "values = [75, 85, 60,90]\n", "\n", - "# Your code here" + "grades_dict = dict(zip(keys, values))\n", + "print(grades_dict)\n" ] }, { @@ -275,11 +436,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chemistry\n" + ] + } + ], "source": [ - "# Your code here" + "lowest_subject = min(grades_dict, key=grades_dict.get)\n", + "print(lowest_subject)" ] } ], @@ -299,7 +469,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.5" } }, "nbformat": 4,