diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8ba652c..b13b581 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -46,22 +46,60 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 1, "metadata": {}, + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the grade for student 1: 9\n", + "Enter the grade for student 2: 8\n", + "Enter the grade for student 3: 5\n", + "Enter the grade for student 4: 5\n", + "Enter the grade for student 5: 3\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All grades: [9, 8, 5, 5, 3]\n", + "Total sum of grades: 30\n", + "Selected grades: [3, 5, 9]\n", + "Length of selected grades: 3\n", + "Number of occurrences of score 5: 1\n" + ] + } + ], "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" + "grades = []\n", + "\n", + "for student_number in range(1, 6):\n", + " grade = int(input(f\"Enter the grade for student {student_number}: \"))\n", + " grades.append(grade)\n", + "\n", + "total_grades = sum(grades)\n", + "\n", + "selected_grades = grades[::2]\n", + "selected_grades.sort()\n", + "\n", + "print(\"All grades:\", grades)\n", + "print(\"Total sum of grades:\", total_grades)\n", + "print(\"Selected grades:\", selected_grades)\n", + "print(\"Length of selected grades:\", len(selected_grades))\n", + "print(\"Number of occurrences of score 5:\", selected_grades.count(5))" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "# Your code here" + "*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" ] }, { @@ -95,11 +133,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First fruit: apple\n", + "Last fruit: grape\n", + "Updated tuple: ('apple', 'strawberry', 'orange', 'mango', 'grape')\n", + "Tuple after adding two fruits: ('apple', 'strawberry', 'orange', 'mango', 'grape', 'pineapple', 'watermelon')\n", + "First three fruits: ('apple', 'strawberry', 'orange')\n", + "Last three fruits: ('grape', 'pineapple', 'watermelon')\n", + "Final tuple: ('apple', 'strawberry', 'orange', 'grape', 'pineapple', 'watermelon', 'apple', 'strawberry', 'orange', 'mango', 'grape')\n", + "Length of final tuple: 11\n" + ] + } + ], "source": [ - "# Your code here" + "# Create a tuple with five fruits\n", + "fruits = (\"apple\", \"banana\", \"orange\", \"mango\", \"grape\")\n", + "\n", + "# Print the first and last fruits\n", + "print(\"First fruit:\", fruits[0])\n", + "print(\"Last fruit:\", fruits[-1])\n", + "\n", + "# Replace the second fruit by creating a new tuple\n", + "fruits = fruits[:1] + (\"strawberry\",) + fruits[2:]\n", + "\n", + "print(\"Updated tuple:\", fruits)\n", + "\n", + "# Add two additional fruits\n", + "additional_fruits = (\"pineapple\", \"watermelon\")\n", + "resulting_tuple = fruits + additional_fruits\n", + "\n", + "print(\"Tuple after adding two fruits:\", resulting_tuple)\n", + "\n", + "# Create one tuple from the first three elements\n", + "first_three = resulting_tuple[:3]\n", + "\n", + "# Create another tuple from the last three elements\n", + "last_three = resulting_tuple[-3:]\n", + "\n", + "print(\"First three fruits:\", first_three)\n", + "print(\"Last three fruits:\", last_three)\n", + "\n", + "# Combine the two smaller tuples with the original updated tuple\n", + "final_tuple = first_three + last_three + fruits\n", + "\n", + "print(\"Final tuple:\", final_tuple)\n", + "print(\"Length of final tuple:\", len(final_tuple))" ] }, { @@ -136,7 +220,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -163,11 +247,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Unique words in the first poem: 41\n", + "Unique words in the second poem: 42\n", + "Words only in the first poem: {'ice', 'in', 'the', 'hate', 'favor', 'world', 'would', 'fire', 'suffice', 'great', 'also', 'desire', 'tasted', 'for', 'perish', 'twice', 'destruction', 'hold', 'will'}\n", + "Words only in the second poem: {'deem', 'as', 'love', 'see', 'we', 'seen', 'fades', 'still', 'today', 'quest', 'side', 'its', 'a', 'away', 'are', 'life', 'test', 'though', 'dream', 'made'}\n", + "Words present in both poems: ['and', 'but', 'end', 'enough', 'from', 'had', 'i', 'if', 'is', 'it', 'ive', 'know', 'of', 'say', 'some', 'that', 'think', 'those', 'to', 'what', 'who', 'with']\n" + ] + } + ], "source": [ - "# Your code here" + "import string\n", + "\n", + "punctuation = string.punctuation + \"’\"\n", + "\n", + "poem_words = set(\n", + " poem.lower()\n", + " .translate(str.maketrans(\"\", \"\", punctuation))\n", + " .split()\n", + ")\n", + "\n", + "new_poem_words = set(\n", + " new_poem.lower()\n", + " .translate(str.maketrans(\"\", \"\", punctuation))\n", + " .split()\n", + ")\n", + "\n", + "print(\"Unique words in the first poem:\", len(poem_words))\n", + "print(\"Unique words in the second poem:\", len(new_poem_words))\n", + "\n", + "print(\"Words only in the first poem:\", poem_words - new_poem_words)\n", + "print(\"Words only in the second poem:\", new_poem_words - poem_words)\n", + "\n", + "print(\"Words present in both poems:\", sorted(poem_words & new_poem_words))" ] }, { @@ -193,7 +311,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -202,11 +320,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "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[\"Bob\"][\"Philosophy\"] = 100\n", + "\n", + "print(grades)" ] }, { @@ -239,7 +367,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -275,19 +403,73 @@ }, { "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": [ - "# Your code here" + "scores = dict(zip(keys, values))\n", + "\n", + "print(scores)" ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Subject with the minimum score: Chemistry\n" + ] + } + ], + "source": [ + "minimum_subject = min(scores, key=scores.get)\n", + "\n", + "print(\"Subject with the minimum score:\", minimum_subject)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "C:\\Users\\LENOVO\\ironhack\\Week_1\\Day1\n" + ] + } + ], + "source": [ + "import os\n", + "print(os.getcwd())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python [conda env:anaconda3] *", "language": "python", - "name": "python3" + "name": "conda-env-anaconda3-py" }, "language_info": { "codemirror_mode": { @@ -299,7 +481,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.13.9" } }, "nbformat": 4,