From 3a69637083b643f4dcac9b14bfac57ab179a3426 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Mon, 6 Oct 2025 18:33:13 +0200 Subject: [PATCH 1/8] Add files via upload --- Lab.Week1.ipynb | 590 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 590 insertions(+) create mode 100644 Lab.Week1.ipynb diff --git a/Lab.Week1.ipynb b/Lab.Week1.ipynb new file mode 100644 index 00000000..64984e02 --- /dev/null +++ b/Lab.Week1.ipynb @@ -0,0 +1,590 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 14, + "id": "7037fc88-ee82-4112-b23a-4e64cdc00597", + "metadata": {}, + "outputs": [], + "source": [ + "my_tuple = (\"I\")" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "8650fa07-2982-4ee1-9579-5904b5d15aa8", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "str" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "type(my_tuple)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "id": "67ba699d-d6d0-4df9-9ad7-fd6a2031c2fb", + "metadata": {}, + "outputs": [], + "source": [ + "my_tuple = (\"I\",\"r\",\"o\",\"n\",\"h\",\"a\",\"c\",\"k\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "id": "cf5194a8-19a1-4f1f-8ec3-29950096d77e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], + "source": [ + "tup1 = my_tuple[:4]\n", + "tup2 = my_tuple[4:]\n", + "print (tup1)\n", + "print (tup2)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "id": "748a8a62-3402-46c0-b305-9fd3b99fa6e5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n", + "tup3 es igual a my_tuple?: True\n" + ] + } + ], + "source": [ + "tup3 = tup1 + tup2 \n", + "print(tup3)\n", + "print(\"tup3 es igual a my_tuple?:\", tup3 == my_tuple)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "id": "5679caca-9546-40cf-8c99-47314d610787", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elementos en tup1: 4\n", + "Elementos en tup2: 4\n", + "Suma de ambos: 8\n", + "Elementos en tup3: 8\n", + "¿La suma es igual al número de elementos en tup3?: True\n" + ] + } + ], + "source": [ + "count1 = len(tup1)\n", + "count2 = len(tup2)\n", + "\n", + "total = count1 + count2 \n", + "\n", + "print(\"Elementos en tup1:\", count1)\n", + "print(\"Elementos en tup2:\", count2)\n", + "print(\"Suma de ambos:\", total)\n", + "print(\"Elementos en tup3:\", len(tup3))\n", + "print(\"¿La suma es igual al número de elementos en tup3?:\", total == len(tup3))" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "id": "95695aaa-82bc-4971-95c2-1c74f10dfdbd", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "El indice de h en tup3 es: 4\n" + ] + } + ], + "source": [ + "index_h = tup3.index(\"h\")\n", + "print(\"El indice de h en tup3 es:\", index_h)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "id": "3d1f4f2a-3ce6-4e98-b0cd-140bb4527f09", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n", + "False\n" + ] + } + ], + "source": [ + "tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for letter in letters:\n", + " print(letter in tup3)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "id": "e09df221-2057-4d9d-a479-f9ae967e66b2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "'a' aparece 1 vez/veces en tup3\n", + "'b' aparece 0 vez/veces en tup3\n", + "'c' aparece 1 vez/veces en tup3\n", + "'d' aparece 0 vez/veces en tup3\n", + "'e' aparece 0 vez/veces en tup3\n" + ] + } + ], + "source": [ + "tup3 = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "\n", + "for letter in letters:\n", + " count = tup3.count(letter)\n", + " print(f\"'{letter}' aparece {count} vez/veces en tup3\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "id": "dc67f1ff-2eb1-45c2-bc85-2f863357021c", + "metadata": {}, + "outputs": [], + "source": [ + "#Challenge 2: Sets \n", + "import random" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "id": "d134e5f5-bf4b-4dc6-ba67-a441307c2eae", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[26, 55, 74, 22, 58, 2, 39, 11, 52, 80, 56, 9, 23, 6, 85, 28, 59, 8, 20, 95, 92, 70, 10, 77, 50, 27, 89, 46, 36, 90, 96, 78, 18, 40, 32, 94, 76, 33, 1, 88, 24, 4, 83, 21, 48, 25, 62, 69, 75, 5, 19, 16, 63, 57, 100, 71, 15, 31, 47, 12, 93, 91, 54, 67, 86, 42, 51, 97, 44, 35, 0, 34, 53, 38, 65, 99, 61, 29, 30, 41]\n" + ] + } + ], + "source": [ + "sample_list_1 = random.sample(range(0,101),80)\n", + "print(sample_list_1)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "id": "72c796ba-6e8e-424c-87b5-43ccd8619517", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Longitud de set1: 80\n" + ] + } + ], + "source": [ + "set1 = set(sample_list_1)\n", + "print(\"Longitud de set1:\", len(set1))" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "id": "a3c2e4b2-d2e2-4654-9c36-b22110ded226", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[28, 71, 66, 30, 77, 61, 90, 8, 86, 96, 18, 67, 58, 39, 91, 89, 27, 82, 2, 39, 14, 91, 53, 56, 90, 71, 19, 98, 87, 84, 42, 58, 66, 54, 92, 5, 3, 47, 61, 91, 61, 52, 92, 57, 39, 93, 31, 51, 2, 60, 23, 8, 19, 82, 75, 92, 6, 81, 35, 67, 91, 71, 95, 68, 10, 3, 95, 0, 34, 75, 25, 95, 42, 7, 61, 1, 45, 35, 4, 61]\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "sample_list_2 = []\n", + "\n", + "for _ in range(80):\n", + " sample_list_2.append(random.randint(0, 100))\n", + "\n", + "print(sample_list_2)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "id": "c109c5df-d152-4b12-8ab4-eca256a349d7", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Longitud de set2: 53\n" + ] + } + ], + "source": [ + "set2 = set(sample_list_2)\n", + "\n", + "print(\"Longitud de set2:\", len(set2))\n" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "id": "d2e354e4-2065-4889-8d7d-6c5e5c06b3d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elementos en set1 pero no en set2: {9, 11, 12, 15, 16, 20, 21, 22, 24, 26, 29, 32, 33, 36, 38, 40, 41, 44, 46, 48, 50, 55, 59, 62, 63, 65, 69, 70, 74, 76, 78, 80, 83, 85, 88, 94, 97, 99, 100}\n" + ] + } + ], + "source": [ + "set3 = set1 - set2\n", + "print(\"Elementos en set1 pero no en set2:\", set3)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "id": "7d06a3b5-57f3-4159-a7e9-bfcc35029494", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elementos en set2 pero no en set1: {66, 3, 68, 98, 7, 45, 14, 81, 82, 84, 87, 60}\n" + ] + } + ], + "source": [ + "set4 = set2 - set1\n", + "print(\"Elementos en set2 pero no en set1:\", set4)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "267557c2-a714-4e71-aa95-f0eed617f522", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elementos compartidos entre set1 y set2: {0, 1, 2, 4, 5, 6, 8, 10, 18, 19, 23, 25, 27, 28, 30, 31, 34, 35, 39, 42, 47, 51, 52, 53, 54, 56, 57, 58, 61, 67, 71, 75, 77, 86, 89, 90, 91, 92, 93, 95, 96}\n" + ] + } + ], + "source": [ + "set5 = set1 & set2\n", + "print(\"Elementos compartidos entre set1 y set2:\", set5)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "id": "0bbaf0f6-0910-48c0-8e0c-a9d7f293e804", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "len(set1): 80\n", + "len(set2): 53\n", + "len(set3): 39\n", + "len(set4): 12\n", + "len(set5): 41\n", + "¿Se cumple la relación? True\n" + ] + } + ], + "source": [ + "print(\"len(set1):\", len(set1))\n", + "print(\"len(set2):\", len(set2))\n", + "print(\"len(set3):\", len(set3))\n", + "print(\"len(set4):\", len(set4))\n", + "print(\"len(set5):\", len(set5))\n", + "\n", + "left_side = len(set1) + len(set2)\n", + "right_side = len(set3) + len(set4) + 2 * len(set5)\n", + "print(\"¿Se cumple la relación?\", left_side == right_side)" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "id": "6fea7444-92d4-471b-8a27-afa6414c2c2f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set6: set()\n", + "Tipo de set6: \n" + ] + } + ], + "source": [ + "set6 = set()\n", + "print(\"set6:\", set6)\n", + "print(\"Tipo de set6:\", type(set6))" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "id": "cd73ba96-f16d-4962-adff-7e93f8ce3ce4", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "set6 después de actualizar: {0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 44, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 65, 67, 69, 70, 71, 74, 75, 76, 77, 78, 80, 83, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100}\n" + ] + } + ], + "source": [ + "set6.update(set3)\n", + "set6.update(set5)\n", + "print(\"set6 después de actualizar:\", set6)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "1451d29e-8e34-4819-8f5e-411fecc122d0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "¿set1 y set6 son iguales?: True\n" + ] + } + ], + "source": [ + "are_equal = set1 == set6\n", + "print(\"¿set1 y set6 son iguales?:\", are_equal)" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "id": "61d8b7fd-1fc9-4cac-98f4-74716fe44492", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "¿set1 contiene set2?: False\n", + "¿set1 contiene set3?: True\n" + ] + } + ], + "source": [ + "contains_set2 = set2.issubset(set1)\n", + "print(\"¿set1 contiene set2?:\", contains_set2)\n", + "contains_set3 = set3.issubset(set1)\n", + "print(\"¿set1 contiene set3?:\", contains_set3)" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "b1a2d948-3a88-4e70-a112-15db0927efe3", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "agg1: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}\n", + "agg2: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 44, 45, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 65, 66, 67, 68, 69, 70, 71, 74, 75, 76, 77, 78, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100}\n", + "¿Las agregaciones son iguales?: True\n" + ] + } + ], + "source": [ + "agg1 = set3.union(set4, set5)\n", + "agg2 = set1.union(set2)\n", + "print(\"agg1:\", agg1)\n", + "print(\"agg2:\", agg2)\n", + "are_equal = agg1 == agg2\n", + "print(\"¿Las agregaciones son iguales?:\", are_equal)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "id": "c50288b1-297f-40d2-bcf8-6c3efa92fda8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elemento eliminado: 0\n", + "set1 después de pop(): {1, 2, 4, 5, 6, 8, 9, 10, 11, 12, 15, 16, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 44, 46, 47, 48, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 65, 67, 69, 70, 71, 74, 75, 76, 77, 78, 80, 83, 85, 86, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100}\n" + ] + } + ], + "source": [ + "removed_element = set1.pop()\n", + "print(\"Elemento eliminado:\", removed_element)\n", + "print(\"set1 después de pop():\", set1)" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "id": "afca41a9-b1e0-4eef-88f2-c91533d677aa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elementos restantes en set1: {2, 4, 5, 6, 8, 10, 12, 15, 16, 18, 20, 22, 23, 24, 25, 26, 27, 28, 30, 32, 33, 34, 35, 36, 38, 40, 42, 44, 46, 47, 48, 50, 52, 53, 54, 55, 56, 57, 58, 62, 63, 65, 67, 70, 74, 75, 76, 77, 78, 80, 83, 85, 86, 88, 90, 92, 93, 94, 95, 96, 97, 100}\n" + ] + } + ], + "source": [ + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "for item in list_to_remove:\n", + " set1.discard(item)\n", + "print(\"Elementos restantes en set1:\", set1)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "ce9556be-770f-4485-954a-bd95b17c5bbc", + "metadata": {}, + "outputs": [], + "source": [ + "#Challenge: Dictionaries\n", + "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "53e23258-fbdf-4cac-8422-3c4087208476", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'a': 8, 'about': 1, 'all': 1, 'although': 3, 'and': 23, 'are': 1, 'at': 1, 'baby': 14, 'backseat': 1, 'bag': 1, 'bar': 1, 'be': 16, 'bedsheets': 3, 'begin': 1, 'best': 1, 'body': 17, 'boy': 2, 'brand': 6, 'can': 1, 'chance': 1, 'club': 1, 'come': 37, 'conversation': 1, 'crazy': 2, 'dance': 1, 'date': 1, 'day': 6, 'discovering': 6, 'do': 3, 'doing': 2, \"don't\": 2, 'drinking': 1, 'driver': 1, 'eat': 1, 'every': 6, 'falling': 3, 'family': 1, 'fast': 1, 'fill': 2, 'find': 1, 'first': 1, 'follow': 6, 'for': 3, 'friends': 1, 'get': 1, 'girl': 2, 'give': 1, 'go': 2, 'going': 1, 'grab': 2, 'hand': 1, 'handmade': 2, 'heart': 3, 'hours': 2, 'how': 1, 'i': 6, \"i'll\": 1, \"i'm\": 23, 'in': 27, 'is': 5, \"isn't\": 1, 'it': 1, 'jukebox': 1, 'just': 1, 'kiss': 1, 'know': 2, 'last': 3, 'lead': 6, 'leave': 1, 'let': 1, \"let's\": 2, 'like': 10, 'love': 25, 'lover': 1, 'magnet': 3, 'make': 1, 'man': 1, 'may': 2, 'me': 10, 'mind': 2, 'much': 2, 'my': 33, 'new': 6, 'night': 3, 'not': 2, 'now': 11, 'of': 6, 'okay': 1, 'on': 40, 'one': 1, 'our': 1, 'out': 1, 'over': 1, 'place': 1, 'plate': 1, 'play': 1, 'pull': 3, 'push': 3, 'put': 3, 'radio': 1, 'room': 3, 'say': 2, 'shape': 6, 'shots': 1, 'singing': 2, 'slow': 1, 'smell': 3, 'so': 2, 'somebody': 2, 'something': 6, 'sour': 1, 'start': 2, 'stop': 1, 'story': 1, 'sweet': 1, 'table': 1, 'take': 1, 'talk': 4, 'taxi': 1, 'tell': 1, 'that': 2, 'the': 18, 'then': 3, 'thrifty': 1, 'to': 2, 'too': 5, 'trust': 1, 'up': 3, 'van': 1, 'waist': 2, 'want': 2, 'was': 2, 'we': 7, \"we're\": 1, 'week': 1, 'were': 3, 'where': 1, 'with': 22, 'you': 16, 'your': 21}\n" + ] + } + ], + "source": [ + "keys = list(word_freq.keys())\n", + "keys.sort()\n", + "word_freq2 = {}\n", + "for key in keys:\n", + " word_freq2[key] = word_freq[key]\n", + "print(word_freq2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "bacebf45-4028-447a-a092-4b18d34aa988", + "metadata": {}, + "outputs": [], + "source": [ + "import operator\n", + "word_freq = {'love': 25, 'conversation': 1, 'every': 6, \"we're\": 1, 'plate': 1, 'sour': 1, 'jukebox': 1, 'now': 11, 'taxi': 1, 'fast': 1, 'bag': 1, 'man': 1, 'push': 3, 'baby': 14, 'going': 1, 'you': 16, \"don't\": 2, 'one': 1, 'mind': 2, 'backseat': 1, 'friends': 1, 'then': 3, 'know': 2, 'take': 1, 'play': 1, 'okay': 1, 'so': 2, 'begin': 1, 'start': 2, 'over': 1, 'body': 17, 'boy': 2, 'just': 1, 'we': 7, 'are': 1, 'girl': 2, 'tell': 1, 'singing': 2, 'drinking': 1, 'put': 3, 'our': 1, 'where': 1, \"i'll\": 1, 'all': 1, \"isn't\": 1, 'make': 1, 'lover': 1, 'get': 1, 'radio': 1, 'give': 1, \"i'm\": 23, 'like': 10, 'can': 1, 'doing': 2, 'with': 22, 'club': 1, 'come': 37, 'it': 1, 'somebody': 2, 'handmade': 2, 'out': 1, 'new': 6, 'room': 3, 'chance': 1, 'follow': 6, 'in': 27, 'may': 2, 'brand': 6, 'that': 2, 'magnet': 3, 'up': 3, 'first': 1, 'and': 23, 'pull': 3, 'of': 6, 'table': 1, 'much': 2, 'last': 3, 'i': 6, 'thrifty': 1, 'grab': 2, 'was': 2, 'driver': 1, 'slow': 1, 'dance': 1, 'the': 18, 'say': 2, 'trust': 1, 'family': 1, 'week': 1, 'date': 1, 'me': 10, 'do': 3, 'waist': 2, 'smell': 3, 'day': 6, 'although': 3, 'your': 21, 'leave': 1, 'want': 2, \"let's\": 2, 'lead': 6, 'at': 1, 'hand': 1, 'how': 1, 'talk': 4, 'not': 2, 'eat': 1, 'falling': 3, 'about': 1, 'story': 1, 'sweet': 1, 'best': 1, 'crazy': 2, 'let': 1, 'too': 5, 'van': 1, 'shots': 1, 'go': 2, 'to': 2, 'a': 8, 'my': 33, 'is': 5, 'place': 1, 'find': 1, 'shape': 6, 'on': 40, 'kiss': 1, 'were': 3, 'night': 3, 'heart': 3, 'for': 3, 'discovering': 6, 'something': 6, 'be': 16, 'bedsheets': 3, 'fill': 2, 'hours': 2, 'stop': 1, 'bar': 1}\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n" + ] + } + ], + "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": 5 +} From 388239263b4e35bc7e2446b4e5201bb2c30b1847 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Mon, 6 Oct 2025 18:52:03 +0200 Subject: [PATCH 2/8] Add files via upload --- Lab2_Week1.ipynb | 240 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 240 insertions(+) create mode 100644 Lab2_Week1.ipynb diff --git a/Lab2_Week1.ipynb b/Lab2_Week1.ipynb new file mode 100644 index 00000000..2a72311c --- /dev/null +++ b/Lab2_Week1.ipynb @@ -0,0 +1,240 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "id": "0276beff-5160-498c-ba99-dc2a9873593f", + "metadata": {}, + "outputs": [], + "source": [ + "#1:Words\n", + "\n", + "words = ['play', 'filling', 'bar', 'theatre', 'easygoing', 'date', 'lead', 'that', 'story', 'island']" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "0b781fdb-6c10-43a9-af09-a7c3e9a66c51", + "metadata": {}, + "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": [ + "for word in words:\n", + " print(word.upper())" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "012233ad-a566-45c7-929d-85fcd4d2c9af", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['filling', 'theatre', 'easygoing', 'story', 'island']\n" + ] + } + ], + "source": [ + "long_words = [] \n", + "for word in words:\n", + " if len(word) >= 5:\n", + " long_words.append(word)\n", + "\n", + "print(long_words)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "c81b3a61-0473-4edd-82d8-91a53e18541c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "theatre\n" + ] + } + ], + "source": [ + "for word in words:\n", + " if word.startswith('t'):\n", + " print(word)\n", + " break " + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "48220f5f-7a47-4497-b479-d7a0413ab632", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n" + ] + } + ], + "source": [ + "#2:Numbers \n", + "\n", + "squares = []\n", + "for i in range(1, 11):\n", + " squares.append(i ** 2)\n", + "\n", + "print(squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "08862f0f-4f9b-4382-9257-7da93c401dba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 9, 25, 49, 81]\n" + ] + } + ], + "source": [ + "odd_squares = [i ** 2 for i in range(1, 11) if i % 2 != 0]\n", + "print(odd_squares)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "b0554ccc-0fd7-4c19-904b-2a6149e4c9d5", + "metadata": {}, + "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": [ + "squares_of_8 = []\n", + "for i in range(8, 1000, 8):\n", + " squares_of_8.append(i ** 2)\n", + "\n", + "print(squares_of_8)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "7f37a9da-2594-490a-8f6d-7207b86b7585", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], + "source": [ + "#3:People \n", + "\n", + "people = [\n", + " {\"name\": \"Juan\", \"age\": 34, \"n_kids\": 2},\n", + " {\"name\": \"Pepe\", \"age\": 27, \"n_kids\": 0},\n", + " {\"name\": \"Sonia\", \"age\": 41, \"n_kids\": 1},\n", + " {\"name\": \"Lucía\", \"age\": 22, \"n_kids\": 2},\n", + " {\"name\": \"Leo\", \"age\": 55, \"n_kids\": 5}\n", + "]\n", + "\n", + "print(len(people))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "b4c63531-9dac-4d0f-b60b-b4b2150653f9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], + "source": [ + "people = [\n", + " {\"name\": \"Juan\", \"age\": 34, \"n_kids\": 2},\n", + " {\"name\": \"Pepe\", \"age\": 27, \"n_kids\": 0},\n", + " {\"name\": \"Sonia\", \"age\": 41, \"n_kids\": 1},\n", + " {\"name\": \"Lucía\", \"age\": 22, \"n_kids\": 2},\n", + " {\"name\": \"Leo\", \"age\": 55, \"n_kids\": 5}\n", + "]\n", + "\n", + "count_with_kids = 0\n", + "for person in people:\n", + " if person[\"n_kids\"] > 0:\n", + " count_with_kids += 1\n", + "print(count_with_kids)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "b7fa7b9a-db6b-4c3d-b947-634db6b2893a", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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": 5 +} From 1136dce6b379a90bb5eacb41391480f6e1df6ada Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Thu, 9 Oct 2025 18:27:34 +0200 Subject: [PATCH 3/8] Add files via upload --- Lab3_Week1.ipynb | 197 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 197 insertions(+) create mode 100644 Lab3_Week1.ipynb diff --git a/Lab3_Week1.ipynb b/Lab3_Week1.ipynb new file mode 100644 index 00000000..cb11b4de --- /dev/null +++ b/Lab3_Week1.ipynb @@ -0,0 +1,197 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "141e093d-43b3-4c51-8e05-beef0689ca20", + "metadata": {}, + "outputs": [], + "source": [ + "import os " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7f769330-eec5-49fc-8d0a-305576d0ed44", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50]\n" + ] + } + ], + "source": [ + "numbers = [i for i in range(1,51)]\n", + "print(numbers)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "2dfbc422-8767-43f6-a629-217a040b71bc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32, 34, 36, 38, 40, 42, 44, 46, 48, 50, 52, 54, 56, 58, 60, 62, 64, 66, 68, 70, 72, 74, 76, 78, 80, 82, 84, 86, 88, 90, 92, 94, 96, 98, 100, 102, 104, 106, 108, 110, 112, 114, 116, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 138, 140, 142, 144, 146, 148, 150, 152, 154, 156, 158, 160, 162, 164, 166, 168, 170, 172, 174, 176, 178, 180, 182, 184, 186, 188, 190, 192, 194, 196, 198, 200]\n" + ] + } + ], + "source": [ + "even_numbers = [i for i in range(2,202,2)]\n", + "print(even_numbers)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "a950a167-bed4-4ed2-b5b9-40293c1243de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.48006452, 0.7876326, 0.77109654, 0.44409793, 0.09014516, 0.81835917, 0.87645456, 0.7066597, 0.09610873, 0.41247947, 0.57433389, 0.29960807, 0.42315023, 0.34452557, 0.4751035, 0.17003563, 0.46843998, 0.92796258, 0.69814654, 0.41290051, 0.19561071, 0.16284783, 0.97016248, 0.71725408, 0.87702738, 0.31244595, 0.76615487, 0.20754036, 0.57871812, 0.07214068, 0.40356048, 0.12149553, 0.53222417, 0.9976855, 0.12536346, 0.80930099, 0.50962849, 0.94555126, 0.33364763]\n" + ] + } + ], + "source": [ + "a = [\n", + " [0.84062117, 0.48006452, 0.7876326 , 0.77109654],\n", + " [0.44409793, 0.09014516, 0.81835917, 0.87645456],\n", + " [0.7066597 , 0.09610873, 0.41247947, 0.57433389],\n", + " [0.29960807, 0.42315023, 0.34452557, 0.4751035 ],\n", + " [0.17003563, 0.46843998, 0.92796258, 0.69814654],\n", + " [0.41290051, 0.19561071, 0.16284783, 0.97016248],\n", + " [0.71725408, 0.87702738, 0.31244595, 0.76615487],\n", + " [0.20754036, 0.57871812, 0.07214068, 0.40356048],\n", + " [0.12149553, 0.53222417, 0.9976855 , 0.12536346],\n", + " [0.80930099, 0.50962849, 0.94555126, 0.33364763]\n", + "]\n", + "flattened = [x for row in a for x in row]\n", + "print(flattened)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "0f2fa452-125f-4d77-a66f-ee6e8d674301", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.7876326, 0.77109654, 0.81835917, 0.87645456, 0.7066597, 0.57433389, 0.92796258, 0.69814654, 0.97016248, 0.71725408, 0.87702738, 0.76615487, 0.57871812, 0.53222417, 0.9976855, 0.80930099, 0.50962849, 0.94555126]\n" + ] + } + ], + "source": [ + "a = [\n", + " [0.84062117, 0.48006452, 0.7876326 , 0.77109654],\n", + " [0.44409793, 0.09014516, 0.81835917, 0.87645456],\n", + " [0.7066597 , 0.09610873, 0.41247947, 0.57433389],\n", + " [0.29960807, 0.42315023, 0.34452557, 0.4751035 ],\n", + " [0.17003563, 0.46843998, 0.92796258, 0.69814654],\n", + " [0.41290051, 0.19561071, 0.16284783, 0.97016248],\n", + " [0.71725408, 0.87702738, 0.31244595, 0.76615487],\n", + " [0.20754036, 0.57871812, 0.07214068, 0.40356048],\n", + " [0.12149553, 0.53222417, 0.9976855 , 0.12536346],\n", + " [0.80930099, 0.50962849, 0.94555126, 0.33364763]\n", + "]\n", + "filtered = [x for row in a for x in row if x >= 0.5]\n", + "print(filtered)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "82280d1e-360f-49af-b184-9e264fa6ce2a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.55867166, 0.06210792, 0.08147297, 0.82579068, 0.91512478, 0.06833034, 0.05440634, 0.65857693, 0.30296619, 0.06769833, 0.96031863, 0.51293743, 0.09143215, 0.71893382, 0.45850679, 0.58256464, 0.59005654, 0.56266457, 0.71600294, 0.87392666, 0.11434044, 0.8694668, 0.65669313, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.65368638, 0.14901286, 0.23760688]\n" + ] + } + ], + "source": [ + "b = [\n", + " [[0.55867166, 0.06210792, 0.08147297],\n", + " [0.82579068, 0.91512478, 0.06833034]],\n", + "\n", + " [[0.05440634, 0.65857693, 0.30296619],\n", + " [0.06769833, 0.96031863, 0.51293743]],\n", + "\n", + " [[0.09143215, 0.71893382, 0.45850679],\n", + " [0.58256464, 0.59005654, 0.56266457]],\n", + "\n", + " [[0.71600294, 0.87392666, 0.11434044],\n", + " [0.8694668 , 0.65669313, 0.10708681]],\n", + "\n", + " [[0.07529684, 0.46470767, 0.47984544],\n", + " [0.65368638, 0.14901286, 0.23760688]]\n", + "]\n", + "flattened = [x for matrix in b for row in matrix for x in row]\n", + "print(flattened)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "c29e948b-c5be-4a3c-bfc2-a5a8bcd97d39", + "metadata": {}, + "outputs": [], + "source": [ + "b = [\n", + " [[0.55867166, 0.06210792, 0.08147297],\n", + " [0.82579068, 0.91512478, 0.06833034]],\n", + "\n", + " [[0.05440634, 0.65857693, 0.30296619],\n", + " [0.06769833, 0.96031863, 0.51293743]],\n", + "\n", + " [[0.09143215, 0.71893382, 0.45850679],\n", + " [0.58256464, 0.59005654, 0.56266457]],\n", + "\n", + " [[0.71600294, 0.87392666, 0.11434044],\n", + " [0.8694668 , 0.65669313, 0.10708681]],\n", + "\n", + " [[0.07529684, 0.46470767, 0.47984544],\n", + " [0.65368638, 0.14901286, 0.23760688]]\n", + "]\n", + "last_values" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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": 5 +} From 2252d924cc9db6d5761a3a804b7863cd7d1e9b6b Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Wed, 15 Oct 2025 21:00:52 +0200 Subject: [PATCH 4/8] Add files via upload --- Lab1_Week3.ipynb | 346 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 346 insertions(+) create mode 100644 Lab1_Week3.ipynb diff --git a/Lab1_Week3.ipynb b/Lab1_Week3.ipynb new file mode 100644 index 00000000..cf2b4857 --- /dev/null +++ b/Lab1_Week3.ipynb @@ -0,0 +1,346 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 3, + "id": "4e7dda1b-c83b-4286-a2fc-81057cb0890a", + "metadata": {}, + "outputs": [], + "source": [ + "from functools import reduce\n", + "import numpy\n", + "import pandas" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "848e37d7-459c-484e-92b6-4c11b0e8d417", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Número de palabras: 13694\n" + ] + } + ], + "source": [ + "import urllib.request\n", + "\n", + "url = \"https://www.gutenberg.org/cache/epub/58585/pg58585.txt\"\n", + "response = urllib.request.urlopen(url)\n", + "prophet = response.read().decode(\"utf8\").split(\" \")\n", + "\n", + "print(\"Número de palabras:\", len(prophet))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "c55c6688-4e11-442f-a4dc-818c831f7573", + "metadata": {}, + "outputs": [], + "source": [ + "prophet = prophet[568:]" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "3c815a30-0959-4d2f-97bc-0bd9b8f67ff5", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['was',\n", + " 'to\\r\\nreturn',\n", + " 'and',\n", + " 'bear',\n", + " 'him',\n", + " 'back',\n", + " 'to',\n", + " 'the',\n", + " 'isle',\n", + " 'of\\r\\nhis']" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet[:10]" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "66466b48-d2de-44fe-9bc2-6d64e4375f7b", + "metadata": {}, + "outputs": [], + "source": [ + "def reference(x):\n", + " '''\n", + " Input: A string\n", + " Output: The string with references removed\n", + " \n", + " Example:\n", + " Input: 'the{7}'\n", + " Output: 'the'\n", + " '''\n", + " parts = x.split('{')\n", + " return parts[0]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "dc2b5a05-960b-417d-b0b0-191ae434a210", + "metadata": {}, + "outputs": [], + "source": [ + "prophet_reference = list(map(reference,prophet))" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "5c1f09b5-e94e-486a-baf8-9519ecf5eee0", + "metadata": {}, + "outputs": [], + "source": [ + "def line_break(x):\n", + " '''\n", + " Input: A string\n", + " Output: A list of strings split on the line break (\\n) character\n", + " \n", + " Example:\n", + " Input: 'the\\nbeloved'\n", + " Output: ['the', 'beloved']\n", + " '''\n", + " return x.split('\\n')" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "09542ab4-5faa-4890-87b8-f5445cc6aecc", + "metadata": {}, + "outputs": [], + "source": [ + "prophet_line = list(map(line_break, prophet_reference))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "17233c76-fd30-42ba-a857-737775ac030c", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['was',\n", + " 'to\\r',\n", + " 'return',\n", + " 'and',\n", + " 'bear',\n", + " 'him',\n", + " 'back',\n", + " 'to',\n", + " 'the',\n", + " 'isle',\n", + " 'of\\r',\n", + " 'his',\n", + " 'birth.\\r',\n", + " '\\r',\n", + " 'And',\n", + " 'in',\n", + " 'the',\n", + " 'twelfth',\n", + " 'year,',\n", + " 'on']" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet_flat = [i for sub in prophet_line for i in sub]\n", + "prophet_flat[:20]" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "e650e1dc-e47d-495d-9d34-a0bbc4110a09", + "metadata": {}, + "outputs": [], + "source": [ + "# Exercise 2 \n", + "def word_filter(x):\n", + " '''\n", + " Input: A string\n", + " Output: True if the word is not in the specified list \n", + " and False if the word is in the list.\n", + " '''\n", + " \n", + " word_list = ['and', 'the', 'a', 'an']\n", + " \n", + " if x in word_list:\n", + " return False\n", + " else:\n", + " return True\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "id": "72c4649f-be1a-4791-8af0-4805031f76b2", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['was',\n", + " 'to\\r',\n", + " 'return',\n", + " 'bear',\n", + " 'him',\n", + " 'back',\n", + " 'to',\n", + " 'isle',\n", + " 'of\\r',\n", + " 'his',\n", + " 'birth.\\r',\n", + " '\\r',\n", + " 'And',\n", + " 'in',\n", + " 'twelfth',\n", + " 'year,',\n", + " 'on',\n", + " 'seventh\\r',\n", + " 'day',\n", + " 'of']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet_filter = list(filter(word_filter, prophet_flat))\n", + "\n", + "prophet_filter[:20]" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "693b6490-51a7-4d9d-b7d3-340d875bf861", + "metadata": {}, + "outputs": [], + "source": [ + "def word_filter_case(x):\n", + " '''\n", + " Same as word_filter, but ignores case.\n", + " '''\n", + " \n", + " word_list = ['and', 'the', 'a', 'an']\n", + " \n", + " if x.lower() in word_list:\n", + " return False\n", + " else:\n", + " return True" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "173ccad8-3ad3-4b91-9c5e-f34a50e06d88", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['was',\n", + " 'to\\r',\n", + " 'return',\n", + " 'bear',\n", + " 'him',\n", + " 'back',\n", + " 'to',\n", + " 'isle',\n", + " 'of\\r',\n", + " 'his',\n", + " 'birth.\\r',\n", + " '\\r',\n", + " 'in',\n", + " 'twelfth',\n", + " 'year,',\n", + " 'on',\n", + " 'seventh\\r',\n", + " 'day',\n", + " 'of',\n", + " 'Ielool,']" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "prophet_filter_case = list(filter(word_filter_case, prophet_flat))\n", + "prophet_filter_case[:20]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4620572b-6a9d-469d-b160-2c9eb2d93884", + "metadata": {}, + "outputs": [], + "source": [ + "def concat_space(a, b):\n", + " '''\n", + " Input: Two strings\n", + " Output: A single string separated by a space\n", + " \n", + " Example:\n", + " Input: 'John', 'Smith'\n", + " Output: 'John Smith'\n", + " '''\n", + " return a + ' ' + b" + ] + } + ], + "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": 5 +} From f1abdf044ffc0f12e2290dcbff55e7097c12c565 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Sat, 18 Oct 2025 12:01:54 +0200 Subject: [PATCH 5/8] Add files via upload --- Vikings.ipynb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 Vikings.ipynb diff --git a/Vikings.ipynb b/Vikings.ipynb new file mode 100644 index 00000000..3f40a367 --- /dev/null +++ b/Vikings.ipynb @@ -0,0 +1,23 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "70c28f5e-52f9-4ebd-97c6-7936da2a8c88", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "", + "name": "" + }, + "language_info": { + "name": "" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} From cabc9c6e90c4ba8100c8972f63fbf8f80a175b48 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Wed, 22 Oct 2025 14:27:20 +0200 Subject: [PATCH 6/8] Add files via upload --- Lab_Numpy.ipynb | 561 +++++++++++++++++++++++++++++++++++ Lab_Week2.ipynb | 767 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1328 insertions(+) create mode 100644 Lab_Numpy.ipynb create mode 100644 Lab_Week2.ipynb diff --git a/Lab_Numpy.ipynb b/Lab_Numpy.ipynb new file mode 100644 index 00000000..e548307b --- /dev/null +++ b/Lab_Numpy.ipynb @@ -0,0 +1,561 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "26232b72-88a8-4e82-aca7-33d05b9fdeee", + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "7cb48f2e-cf61-4b4e-8bfd-b4c52472bba2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "NumPy version: 2.1.3\n", + "Build Dependencies:\n", + " blas:\n", + " detection method: pkgconfig\n", + " found: true\n", + " include directory: C:/Users/alvas/anaconda3/Library/include\n", + " lib directory: C:/Users/alvas/anaconda3/Library/lib\n", + " name: mkl-sdl\n", + " openblas configuration: unknown\n", + " pc file directory: C:\\b\\abs_25aj347ekn\\croot\\numpy_and_numpy_base_1730835595898\\_h_env\\Library\\lib\\pkgconfig\n", + " version: '2023.1'\n", + " lapack:\n", + " detection method: pkgconfig\n", + " found: true\n", + " include directory: C:/Users/alvas/anaconda3/Library/include\n", + " lib directory: C:/Users/alvas/anaconda3/Library/lib\n", + " name: mkl-sdl\n", + " openblas configuration: unknown\n", + " pc file directory: C:\\b\\abs_25aj347ekn\\croot\\numpy_and_numpy_base_1730835595898\\_h_env\\Library\\lib\\pkgconfig\n", + " version: '2023.1'\n", + "Compilers:\n", + " c:\n", + " commands: cl.exe\n", + " linker: link\n", + " name: msvc\n", + " version: 19.29.30156\n", + " c++:\n", + " commands: cl.exe\n", + " linker: link\n", + " name: msvc\n", + " version: 19.29.30156\n", + " cython:\n", + " commands: cython\n", + " linker: cython\n", + " name: cython\n", + " version: 3.0.11\n", + "Machine Information:\n", + " build:\n", + " cpu: x86_64\n", + " endian: little\n", + " family: x86_64\n", + " system: windows\n", + " host:\n", + " cpu: x86_64\n", + " endian: little\n", + " family: x86_64\n", + " system: windows\n", + "Python Information:\n", + " path: C:\\b\\abs_25aj347ekn\\croot\\numpy_and_numpy_base_1730835595898\\_h_env\\python.exe\n", + " version: '3.13'\n", + "SIMD Extensions:\n", + " baseline:\n", + " - SSE\n", + " - SSE2\n", + " - SSE3\n", + " found:\n", + " - SSSE3\n", + " - SSE41\n", + " - POPCNT\n", + " - SSE42\n", + " - AVX\n", + " - F16C\n", + " - FMA3\n", + " - AVX2\n", + " not found:\n", + " - AVX512F\n", + " - AVX512CD\n", + " - AVX512_SKX\n", + " - AVX512_CLX\n", + " - AVX512_CNL\n", + " - AVX512_ICL\n", + "\n" + ] + } + ], + "source": [ + "print(\"NumPy version:\", np.__version__)\n", + "\n", + "np.show_config()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "fceb0a0c-3dd8-4892-b398-d497dc3ac2d5", + "metadata": {}, + "outputs": [], + "source": [ + "a = np.random.random((2, 3, 5))" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "49923ff9-303e-48e2-aabe-b1b4f4dfbc2e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[0.05652156 0.72038546 0.54908194 0.7835943 0.30128941]\n", + " [0.9288521 0.77829971 0.30037226 0.57455895 0.45591454]\n", + " [0.24763384 0.92230717 0.83622236 0.83064687 0.34097221]]\n", + "\n", + " [[0.56261733 0.84694282 0.86305442 0.90414497 0.75006972]\n", + " [0.13504569 0.40345086 0.30487524 0.6616755 0.56885306]\n", + " [0.00778184 0.40087664 0.29053672 0.70303045 0.53025395]]]\n" + ] + } + ], + "source": [ + "print (a)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "bcdcb766-8456-457b-9e50-d6726fbda124", + "metadata": {}, + "outputs": [], + "source": [ + "b = np.ones((5, 2, 3))" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "a0d2554b-a736-4a3c-8b38-e7f0514aeb70", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]\n", + "\n", + " [[1. 1. 1.]\n", + " [1. 1. 1.]]]\n" + ] + } + ], + "source": [ + "print(b)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "9577aded-786f-44cb-ae37-92707f078247", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Size of a: 30\n", + "Size of b: 30\n", + "Do a and b have the same size? True\n" + ] + } + ], + "source": [ + "print(\"Size of a:\", a.size)\n", + "print(\"Size of b:\", b.size)\n", + "\n", + "print(\"Do a and b have the same size?\", a.size == b.size)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "58668c92-caaf-4b36-ab62-b51b78871964", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of a: (2, 3, 5)\n", + "Shape of b: (5, 2, 3)\n", + "a and b cannot be added. Reason: operands could not be broadcast together with shapes (2,3,5) (5,2,3) \n" + ] + } + ], + "source": [ + "print(\"Shape of a:\", a.shape)\n", + "print(\"Shape of b:\", b.shape)\n", + "\n", + "try:\n", + " c = a + b\n", + " print(\"a and b can be added. Result shape:\", c.shape)\n", + "except ValueError as e:\n", + " print(\"a and b cannot be added. Reason:\", e)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "81147791-0f43-45d3-a002-ae8fa579df0d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of c: (2, 3, 5)\n" + ] + } + ], + "source": [ + "c = np.transpose(b, (1, 2, 0))\n", + "\n", + "print(\"Shape of c:\", c.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "1fb5f121-abb0-43a5-b395-bfc281aa32e5", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of d: (2, 3, 5)\n", + "d = [[[1.05652156 1.72038546 1.54908194 1.7835943 1.30128941]\n", + " [1.9288521 1.77829971 1.30037226 1.57455895 1.45591454]\n", + " [1.24763384 1.92230717 1.83622236 1.83064687 1.34097221]]\n", + "\n", + " [[1.56261733 1.84694282 1.86305442 1.90414497 1.75006972]\n", + " [1.13504569 1.40345086 1.30487524 1.6616755 1.56885306]\n", + " [1.00778184 1.40087664 1.29053672 1.70303045 1.53025395]]]\n" + ] + } + ], + "source": [ + "d = a + c\n", + "\n", + "print(\"Shape of d:\", d.shape)\n", + "print(\"d =\", d)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "ddf14e66-717a-42fa-9d7a-cfe97c766004", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Array a:\n", + "[[[0.05652156 0.72038546 0.54908194 0.7835943 0.30128941]\n", + " [0.9288521 0.77829971 0.30037226 0.57455895 0.45591454]\n", + " [0.24763384 0.92230717 0.83622236 0.83064687 0.34097221]]\n", + "\n", + " [[0.56261733 0.84694282 0.86305442 0.90414497 0.75006972]\n", + " [0.13504569 0.40345086 0.30487524 0.6616755 0.56885306]\n", + " [0.00778184 0.40087664 0.29053672 0.70303045 0.53025395]]]\n", + "\n", + "Array d (a + c):\n", + "[[[1.05652156 1.72038546 1.54908194 1.7835943 1.30128941]\n", + " [1.9288521 1.77829971 1.30037226 1.57455895 1.45591454]\n", + " [1.24763384 1.92230717 1.83622236 1.83064687 1.34097221]]\n", + "\n", + " [[1.56261733 1.84694282 1.86305442 1.90414497 1.75006972]\n", + " [1.13504569 1.40345086 1.30487524 1.6616755 1.56885306]\n", + " [1.00778184 1.40087664 1.29053672 1.70303045 1.53025395]]]\n" + ] + } + ], + "source": [ + "print(\"Array a:\")\n", + "print(a)\n", + "\n", + "print(\"\\nArray d (a + c):\")\n", + "print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "d6700836-9d18-44ea-8857-da414ec8aa7e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of e: (2, 3, 5)\n", + "e = [[[0.05652156 0.72038546 0.54908194 0.7835943 0.30128941]\n", + " [0.9288521 0.77829971 0.30037226 0.57455895 0.45591454]\n", + " [0.24763384 0.92230717 0.83622236 0.83064687 0.34097221]]\n", + "\n", + " [[0.56261733 0.84694282 0.86305442 0.90414497 0.75006972]\n", + " [0.13504569 0.40345086 0.30487524 0.6616755 0.56885306]\n", + " [0.00778184 0.40087664 0.29053672 0.70303045 0.53025395]]]\n" + ] + } + ], + "source": [ + "e = a * c\n", + "\n", + "print(\"Shape of e:\", e.shape)\n", + "print(\"e =\", e)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "54f0b220-b85d-4521-a425-879949104207", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Does e equal a? True\n" + ] + } + ], + "source": [ + "print(\"Does e equal a?\", np.array_equal(e, a))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "4c7154ba-de07-4d70-92f4-a553ce1f344f", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "d_max = 1.9288520989287345\n", + "d_min = 1.0077818363185924\n", + "d_mean = 1.5519953966522906\n" + ] + } + ], + "source": [ + "d_max = np.max(d)\n", + "\n", + "d_min = np.min(d)\n", + "\n", + "d_mean = np.mean(d)\n", + "\n", + "print(\"d_max =\", d_max)\n", + "print(\"d_min =\", d_min)\n", + "print(\"d_mean =\", d_mean)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "id": "a56ebe8c-21c2-461c-b4ea-b2416b0ed185", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Shape of f: (2, 3, 5)\n" + ] + } + ], + "source": [ + "f = np.empty(d.shape)\n", + "\n", + "print(\"Shape of f:\", f.shape)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "id": "0d7fde2c-c42e-4afa-b517-3088cf28e518", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Labeled array f:\n", + "[[[ 25. 75. 25. 75. 25.]\n", + " [100. 75. 25. 75. 25.]\n", + " [ 25. 75. 75. 75. 25.]]\n", + "\n", + " [[ 75. 75. 75. 75. 75.]\n", + " [ 25. 25. 25. 75. 75.]\n", + " [ 0. 25. 25. 75. 25.]]]\n" + ] + } + ], + "source": [ + "shape = d.shape\n", + "\n", + "for i in range(shape[0]):\n", + " for j in range(shape[1]):\n", + " for k in range(shape[2]):\n", + " if d[i, j, k] == d_min:\n", + " f[i, j, k] = 0\n", + " elif d[i, j, k] == d_max:\n", + " f[i, j, k] = 100\n", + " elif d[i, j, k] == d_mean:\n", + " f[i, j, k] = 50\n", + " elif d_min < d[i, j, k] < d_mean:\n", + " f[i, j, k] = 25\n", + " elif d_mean < d[i, j, k] < d_max:\n", + " f[i, j, k] = 75\n", + "\n", + "print(\"Labeled array f:\")\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "id": "1e0722c4-0abf-4a72-ba91-1827126161ce", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Array d:\n", + "[[[1.05652156 1.72038546 1.54908194 1.7835943 1.30128941]\n", + " [1.9288521 1.77829971 1.30037226 1.57455895 1.45591454]\n", + " [1.24763384 1.92230717 1.83622236 1.83064687 1.34097221]]\n", + "\n", + " [[1.56261733 1.84694282 1.86305442 1.90414497 1.75006972]\n", + " [1.13504569 1.40345086 1.30487524 1.6616755 1.56885306]\n", + " [1.00778184 1.40087664 1.29053672 1.70303045 1.53025395]]]\n", + "\n", + "Labeled array f:\n", + "[[[ 25. 75. 25. 75. 25.]\n", + " [100. 75. 25. 75. 25.]\n", + " [ 25. 75. 75. 75. 25.]]\n", + "\n", + " [[ 75. 75. 75. 75. 75.]\n", + " [ 25. 25. 25. 75. 75.]\n", + " [ 0. 25. 25. 75. 25.]]]\n" + ] + } + ], + "source": [ + "print(\"Array d:\")\n", + "print(d)\n", + "\n", + "print(\"\\nLabeled array f:\")\n", + "print(f)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "id": "6e0303f4-31ea-45d4-9453-d58429f638b9", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Labeled array with strings:\n", + "[[['B' 'D' 'B' 'D' 'B']\n", + " ['E' 'D' 'B' 'D' 'B']\n", + " ['B' 'D' 'D' 'D' 'B']]\n", + "\n", + " [['D' 'D' 'D' 'D' 'D']\n", + " ['B' 'B' 'B' 'D' 'D']\n", + " ['A' 'B' 'B' 'D' 'B']]]\n" + ] + } + ], + "source": [ + "f_str = np.empty(d.shape, dtype=object)\n", + "\n", + "for i in range(d.shape[0]):\n", + " for j in range(d.shape[1]):\n", + " for k in range(d.shape[2]):\n", + " if d[i, j, k] == d_min:\n", + " f_str[i, j, k] = \"A\"\n", + " elif d[i, j, k] == d_max:\n", + " f_str[i, j, k] = \"E\"\n", + " elif d[i, j, k] == d_mean:\n", + " f_str[i, j, k] = \"C\"\n", + " elif d_min < d[i, j, k] < d_mean:\n", + " f_str[i, j, k] = \"B\"\n", + " elif d_mean < d[i, j, k] < d_max:\n", + " f_str[i, j, k] = \"D\"\n", + "\n", + "print(\"Labeled array with strings:\")\n", + "print(f_str)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74d8dbd1-f399-4ffa-8ad2-0fc4fa5df8fa", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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": 5 +} diff --git a/Lab_Week2.ipynb b/Lab_Week2.ipynb new file mode 100644 index 00000000..ca640827 --- /dev/null +++ b/Lab_Week2.ipynb @@ -0,0 +1,767 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "257455a1-632f-464c-b354-64c3d2433619", + "metadata": {}, + "outputs": [], + "source": [ + "from mod.testing import *\n", + "import unittest" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "5010ce0c-541f-4a71-b41d-ef4d5f00f950", + "metadata": {}, + "outputs": [], + "source": [ + "def greater(a, b):\n", + " if a > b:\n", + " return a\n", + " else:\n", + " return b" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7cad1e95-1782-46ff-85b4-7d54aaf4cf34", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.138s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "test_greater(greater)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "0a4447d3-b39a-4d26-ac5b-d671a5117292", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.154s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def greatest(lst):\n", + " greatest_so_far = lst[0]\n", + " \n", + " for item in lst:\n", + " if item > greatest_so_far:\n", + " greatest_so_far = item\n", + " \n", + " return greatest_so_far\n", + "test_greatest(greatest)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "18cf82f0-9026-4c7c-8c7c-57d3601c7aec", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.152s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def sum_all(lst):\n", + " total = 0\n", + " for item in lst:\n", + " total += item\n", + " return total\n", + "test_sum(sum_all)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "48183fca-f3d4-4494-9c33-fe9b74a57583", + "metadata": {}, + "outputs": [], + "source": [ + "def mult_all(lst):\n", + " product = 1\n", + " for item in lst:\n", + " product *= item\n", + " return product\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "edb3dd76-0ba7-4880-9eea-6f6db76753b6", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.169s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "test_mult(mult_all)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "3f1cf149-9b0b-473d-ae9b-008a58772cb0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.135s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def oper_all(arr, oper = \"*\"):\n", + " if oper == \"+\":\n", + " result = 0\n", + " for item in arr:\n", + " result += item\n", + " else:\n", + " result = 1\n", + " for item in arr:\n", + " result *= item\n", + " return result\n", + "\n", + "test_operations(oper_all)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "262c1a39-daaf-4a52-a267-bd044a54c535", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.151s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def factorial(n):\n", + " result = 1\n", + " for i in range(1, n + 1):\n", + " result *= i\n", + " return result\n", + "\n", + "test_factorial(factorial)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "a9e7a915-a674-4ef4-b858-0354af6a6aa0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.473s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def unique(lst_un):\n", + " result = []\n", + " for item in lst_un:\n", + " found = False\n", + " for r in result:\n", + " if item == r:\n", + " found = True\n", + " break\n", + " if not found:\n", + " result.append(item)\n", + " return result\n", + "\n", + "test_unique(unique)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "id": "05537140-8efc-4661-8125-da76325f4263", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.175s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def mode_counter(arr):\n", + " elements = [] \n", + " frequencies = [] \n", + "\n", + " for item in arr:\n", + " found = False\n", + " for i in range(len(elements)):\n", + " if elements[i] == item:\n", + " frequencies[i] += 1\n", + " found = True\n", + " break\n", + " if not found:\n", + " elements.append(item)\n", + " frequencies.append(1)\n", + "\n", + " max_index = 0\n", + " for i in range(1, len(frequencies)):\n", + " if frequencies[i] > frequencies[max_index]:\n", + " max_index = i\n", + "\n", + " return elements[max_index]\n", + "\n", + "test_mode(mode_counter)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "id": "2fcd87ac-7215-4122-a8aa-1f4009dd049f", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "FFF..F.FF...F..........F...F..FFFF.F.FF..........F..FFF...F....FF.F.......F.F.FFF.............F..F.F\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 661.069218355118 != 676.4892430086621 within 5 delta (15.420024653544147 difference) : Should be 676.4892430086621\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 578.0610537387715 != 598.8907328470777 within 5 delta (20.82967910830621 difference) : Should be 598.8907328470777\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 540.7273523863964 != 559.1363067480142 within 5 delta (18.408954361617816 difference) : Should be 559.1363067480142\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 575.7787024071519 != 585.4016969785763 within 5 delta (9.622994571424442 difference) : Should be 585.4016969785763\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 523.3153126113228 != 548.4228461523263 within 5 delta (25.107533541003477 difference) : Should be 548.4228461523263\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 595.6087272633463 != 609.0773623550077 within 5 delta (13.46863509166144 difference) : Should be 609.0773623550077\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 603.9948425791288 != 609.1617767927277 within 5 delta (5.166934213598893 difference) : Should be 609.1617767927277\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 587.3954880868966 != 594.869941297107 within 5 delta (7.474453210210299 difference) : Should be 594.869941297107\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 529.0607688663242 != 535.0121754451617 within 5 delta (5.951406578837464 difference) : Should be 535.0121754451617\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 601.7476270960531 != 629.7440894377796 within 5 delta (27.996462341726556 difference) : Should be 629.7440894377796\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 536.7649152800452 != 550.942546966995 within 5 delta (14.17763168694978 difference) : Should be 550.942546966995\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 613.9915233209238 != 620.684642980068 within 5 delta (6.6931196591442585 difference) : Should be 620.684642980068\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 539.3280204796041 != 551.468831661747 within 5 delta (12.140811182142897 difference) : Should be 551.468831661747\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 511.84221615511456 != 534.2459994036342 within 5 delta (22.40378324851963 difference) : Should be 534.2459994036342\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 514.497341259944 != 525.1986511677327 within 5 delta (10.70130990778864 difference) : Should be 525.1986511677327\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 508.06449778530873 != 515.8702862326361 within 5 delta (7.805788447327359 difference) : Should be 515.8702862326361\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 510.5899409358518 != 519.6200216804747 within 5 delta (9.030080744622865 difference) : Should be 519.6200216804747\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 565.5993821185207 != 592.3655044894924 within 5 delta (26.766122370971743 difference) : Should be 592.3655044894924\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 677.764477677945 != 694.2020505069864 within 5 delta (16.437572829041414 difference) : Should be 694.2020505069864\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 547.977583500413 != 553.5465799385054 within 5 delta (5.568996438092427 difference) : Should be 553.5465799385054\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 593.7738650054687 != 599.7757575540991 within 5 delta (6.001892548630394 difference) : Should be 599.7757575540991\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 518.0176504545857 != 523.358544578738 within 5 delta (5.340894124152328 difference) : Should be 523.358544578738\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 500.00129528188086 != 526.7572074073173 within 5 delta (26.755912125436453 difference) : Should be 526.7572074073173\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 496.3645796501452 != 506.33700898380584 within 5 delta (9.97242933366067 difference) : Should be 506.33700898380584\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 672.6545689648998 != 688.043552273082 within 5 delta (15.388983308182219 difference) : Should be 688.043552273082\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 580.3810486987429 != 595.2712144169667 within 5 delta (14.890165718223784 difference) : Should be 595.2712144169667\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 581.1889238642547 != 590.8379250722686 within 5 delta (9.649001208013942 difference) : Should be 590.8379250722686\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 521.6096069323795 != 526.966062855063 within 5 delta (5.3564559226834945 difference) : Should be 526.966062855063\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 562.7067660591376 != 570.930274222863 within 5 delta (8.223508163725342 difference) : Should be 570.930274222863\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 660.8177909114846 != 672.3583844211726 within 5 delta (11.540593509687938 difference) : Should be 672.3583844211726\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 559.8113954199302 != 572.8816548609237 within 5 delta (13.070259440993482 difference) : Should be 572.8816548609237\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"C:\\Users\\alvas\\LAB\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + " ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n", + "AssertionError: 586.3516762779275 != 594.0832607281254 within 5 delta (7.731584450197943 difference) : Should be 594.0832607281254\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.188s\n", + "\n", + "FAILED (failures=32)\n" + ] + } + ], + "source": [ + "def st_dev(list_sd):\n", + " total = 0\n", + " count = 0\n", + " for item in list_sd:\n", + " total += item\n", + " count += 1\n", + " mean = total / count\n", + "\n", + " variance_sum = 0\n", + " for item in list_sd:\n", + " diff = item - mean\n", + " variance_sum += diff * diff\n", + " variance = variance_sum / count\n", + "\n", + " guess = variance / 2 if variance > 1 else 1 \n", + " for _ in range(10): \n", + " guess = (guess + variance / guess) / 2\n", + "\n", + " return guess\n", + "\n", + "test_stdev(st_dev)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "id": "fed598f3-194d-4268-85c6-530e128aa6d0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.049s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def pangram(string):\n", + " string = string.lower()\n", + " \n", + " for char_code in range(ord('a'), ord('z') + 1):\n", + " letter = chr(char_code)\n", + " \n", + " found = False\n", + " for ch in string:\n", + " if ch == letter:\n", + " found = True\n", + " break\n", + " \n", + " if not found:\n", + " return False\n", + " \n", + " return True\n", + "\n", + "test_pangram(pangram)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "id": "62f988da-59e9-43a3-b00c-161f538bcd61", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.158s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def sort_alpha(string):\n", + " words = []\n", + " current_word = \"\"\n", + " for char in string:\n", + " if char == \",\":\n", + " words.append(current_word)\n", + " current_word = \"\"\n", + " else:\n", + " current_word += char\n", + " words.append(current_word) \n", + "\n", + " words_sorted = sorted(words)\n", + "\n", + " result = \"\"\n", + " for i in range(len(words_sorted)):\n", + " result += words_sorted[i]\n", + " if i != len(words_sorted) - 1:\n", + " result += \",\"\n", + " \n", + " return result\n", + "\n", + "test_alpha(sort_alpha)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "id": "36da2e0c-fec8-4e46-9ee8-63b48a0885c0", + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.162s\n", + "\n", + "OK\n" + ] + } + ], + "source": [ + "def check_pass(password):\n", + " if len(password) < 8:\n", + " return False\n", + "\n", + " has_lower = False\n", + " has_upper = False\n", + " has_number = False\n", + " has_special = False\n", + "\n", + " for char in password:\n", + " if 'a' <= char <= 'z':\n", + " has_lower = True\n", + " elif 'A' <= char <= 'Z':\n", + " has_upper = True\n", + " elif '0' <= char <= '9':\n", + " has_number = True\n", + " else:\n", + " has_special = True\n", + "\n", + " return has_lower and has_upper and has_number and has_special\n", + "\n", + "test_pass(check_pass)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "58422125-973c-4a7d-878d-c54bea7a8739", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python [conda env:base] *", + "language": "python", + "name": "conda-base-py" + }, + "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": 5 +} From c4be31e7b2a9d5142cdecf19665ccb2d2824ffe0 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Thu, 23 Oct 2025 21:27:52 +0200 Subject: [PATCH 7/8] Add files via upload --- Lab1_Week4.ipynb | 455 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 455 insertions(+) create mode 100644 Lab1_Week4.ipynb diff --git a/Lab1_Week4.ipynb b/Lab1_Week4.ipynb new file mode 100644 index 00000000..4c39e975 --- /dev/null +++ b/Lab1_Week4.ipynb @@ -0,0 +1,455 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "771da007-54ee-4761-90ee-829a5a9ca5c4", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd\n", + "import numpy as np" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "fa02bd9c-f9bb-4ef8-b500-fc702cf0e5b0", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 5.7\n", + "1 75.2\n", + "2 74.4\n", + "3 84.0\n", + "4 66.5\n", + "5 66.3\n", + "6 55.8\n", + "7 75.7\n", + "8 29.1\n", + "9 43.7\n", + "dtype: float64\n" + ] + } + ], + "source": [ + "lst = [5.7, 75.2, 74.4, 84.0, 66.5, 66.3, 55.8, 75.7, 29.1, 43.7]\n", + "\n", + "series = pd.Series(lst)\n", + "print(series)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "d23f18af-dd7f-4916-b321-ab49e5c91607", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "74.4\n" + ] + } + ], + "source": [ + "third_value = series[2]\n", + "print(third_value)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4b552a6c-3cb5-4142-9e17-7f0eb6858c53", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 0 1 2 3 4\n", + "0 53.1 95.0 67.5 35.0 78.4\n", + "1 61.3 40.8 30.8 37.8 87.6\n", + "2 20.6 73.2 44.2 14.6 91.8\n", + "3 57.4 0.1 96.1 4.2 69.5\n", + "4 83.6 20.5 85.4 22.8 35.9\n", + "5 49.0 69.0 0.1 31.8 89.1\n", + "6 23.3 40.7 95.0 83.8 26.9\n", + "7 27.6 26.4 53.8 88.8 68.5\n", + "8 96.6 96.4 53.4 72.4 50.1\n", + "9 73.7 39.0 43.2 81.6 34.7\n" + ] + } + ], + "source": [ + "b = [[53.1, 95.0, 67.5, 35.0, 78.4],\n", + " [61.3, 40.8, 30.8, 37.8, 87.6],\n", + " [20.6, 73.2, 44.2, 14.6, 91.8],\n", + " [57.4, 0.1, 96.1, 4.2, 69.5],\n", + " [83.6, 20.5, 85.4, 22.8, 35.9],\n", + " [49.0, 69.0, 0.1, 31.8, 89.1],\n", + " [23.3, 40.7, 95.0, 83.8, 26.9],\n", + " [27.6, 26.4, 53.8, 88.8, 68.5],\n", + " [96.6, 96.4, 53.4, 72.4, 50.1],\n", + " [73.7, 39.0, 43.2, 81.6, 34.7]]\n", + "\n", + "df = pd.DataFrame(b)\n", + "print(df)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "ed5ea86b-c3df-491c-9a8d-f8b5348763e8", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " A B C D E\n", + "0 53.1 95.0 67.5 35.0 78.4\n", + "1 61.3 40.8 30.8 37.8 87.6\n", + "2 20.6 73.2 44.2 14.6 91.8\n", + "3 57.4 0.1 96.1 4.2 69.5\n", + "4 83.6 20.5 85.4 22.8 35.9\n", + "5 49.0 69.0 0.1 31.8 89.1\n", + "6 23.3 40.7 95.0 83.8 26.9\n", + "7 27.6 26.4 53.8 88.8 68.5\n", + "8 96.6 96.4 53.4 72.4 50.1\n", + "9 73.7 39.0 43.2 81.6 34.7\n" + ] + } + ], + "source": [ + "b = [[53.1, 95.0, 67.5, 35.0, 78.4],\n", + " [61.3, 40.8, 30.8, 37.8, 87.6],\n", + " [20.6, 73.2, 44.2, 14.6, 91.8],\n", + " [57.4, 0.1, 96.1, 4.2, 69.5],\n", + " [83.6, 20.5, 85.4, 22.8, 35.9],\n", + " [49.0, 69.0, 0.1, 31.8, 89.1],\n", + " [23.3, 40.7, 95.0, 83.8, 26.9],\n", + " [27.6, 26.4, 53.8, 88.8, 68.5],\n", + " [96.6, 96.4, 53.4, 72.4, 50.1],\n", + " [73.7, 39.0, 43.2, 81.6, 34.7]]\n", + "\n", + "column_names = ['A', 'B', 'C', 'D', 'E']\n", + "\n", + "df = pd.DataFrame(b, columns=column_names)\n", + "print(df)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "id": "61cfeb11-15a1-449c-9c9a-e58dda2efda1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " A C E\n", + "0 53.1 67.5 78.4\n", + "1 61.3 30.8 87.6\n", + "2 20.6 44.2 91.8\n", + "3 57.4 96.1 69.5\n", + "4 83.6 85.4 35.9\n", + "5 49.0 0.1 89.1\n", + "6 23.3 95.0 26.9\n", + "7 27.6 53.8 68.5\n", + "8 96.6 53.4 50.1\n", + "9 73.7 43.2 34.7\n" + ] + } + ], + "source": [ + "subset_df = df[['A', 'C', 'E']]\n", + "print(subset_df)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "id": "f35861c9-19c8-442a-bbe0-e7de0c44d39e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "56.95000000000001\n" + ] + } + ], + "source": [ + "average_score3 = df['C'].mean()\n", + "print(average_score3)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "id": "5cfd4562-07d9-4d03-83d4-1f3cf3d93c43", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "88.8\n" + ] + } + ], + "source": [ + "max_score4 = df['D'].max()\n", + "print(max_score4)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "id": "04bdc8c1-d0ca-4ec8-b918-bf369bbdc793", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "40.75\n" + ] + } + ], + "source": [ + "median_score2 = df['B'].median()\n", + "print(median_score2)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "id": "9c25a9d3-356f-474a-b5fb-f84ffbbebc60", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Description Quantity UnitPrice Revenue\n", + "0 LUNCH BAG APPLE DESIGN 1 1.65 1.65\n", + "1 SET OF 60 VINTAGE LEAF CAKE CASES 24 0.55 13.20\n", + "2 RIBBON REEL STRIPES DESIGN 1 1.65 1.65\n", + "3 WORLD WAR 2 GLIDERS ASSTD DESIGNS 2880 0.18 518.40\n", + "4 PLAYING CARDS JUBILEE UNION JACK 2 1.25 2.50\n", + "5 POPCORN HOLDER 7 0.85 5.95\n", + "6 BOX OF VINTAGE ALPHABET BLOCKS 1 11.95 11.95\n", + "7 PARTY BUNTING 4 4.95 19.80\n", + "8 JAZZ HEARTS ADDRESS BOOK 10 0.19 1.90\n", + "9 SET OF 4 SANTA PLACE SETTINGS 48 1.25 60.00\n" + ] + } + ], + "source": [ + "orders = {'Description': ['LUNCH BAG APPLE DESIGN',\n", + " 'SET OF 60 VINTAGE LEAF CAKE CASES ',\n", + " 'RIBBON REEL STRIPES DESIGN ',\n", + " 'WORLD WAR 2 GLIDERS ASSTD DESIGNS',\n", + " 'PLAYING CARDS JUBILEE UNION JACK',\n", + " 'POPCORN HOLDER',\n", + " 'BOX OF VINTAGE ALPHABET BLOCKS',\n", + " 'PARTY BUNTING',\n", + " 'JAZZ HEARTS ADDRESS BOOK',\n", + " 'SET OF 4 SANTA PLACE SETTINGS'],\n", + " 'Quantity': [1, 24, 1, 2880, 2, 7, 1, 4, 10, 48],\n", + " 'UnitPrice': [1.65, 0.55, 1.65, 0.18, 1.25, 0.85, 11.95, 4.95, 0.19, 1.25],\n", + " 'Revenue': [1.65, 13.2, 1.65, 518.4, 2.5, 5.95, 11.95, 19.8, 1.9, 60.0]}\n", + "\n", + "df_orders = pd.DataFrame(orders)\n", + "print(df_orders)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "id": "e538d9d8-5e06-419d-be69-0b58912dc4de", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Total Quantity Ordered: 2978\n", + "Total Revenue Generated: 637.0\n" + ] + } + ], + "source": [ + "total_quantity = df_orders['Quantity'].sum()\n", + "total_revenue = df_orders['Revenue'].sum()\n", + "\n", + "print(\"Total Quantity Ordered:\", total_quantity)\n", + "print(\"Total Revenue Generated:\", total_revenue)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "id": "f78275dc-fea1-4d8c-9416-d2b9cd7d873e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Most Expensive Item Price: 11.95\n", + "Least Expensive Item Price: 0.18\n", + "Price Difference: 11.77\n" + ] + } + ], + "source": [ + "max_price = df_orders['UnitPrice'].max()\n", + "min_price = df_orders['UnitPrice'].min()\n", + "price_difference = max_price - min_price\n", + "\n", + "print(\"Most Expensive Item Price:\", max_price)\n", + "print(\"Least Expensive Item Price:\", min_price)\n", + "print(\"Price Difference:\", price_difference)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "863503fa-3aff-4817-b3c4-ce516c20249e", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'pd' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m admissions \u001b[38;5;241m=\u001b[39m pd\u001b[38;5;241m.\u001b[39mread_csv(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m../Admission_Predict.csv\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(admissions\u001b[38;5;241m.\u001b[39mhead())\n", + "\u001b[1;31mNameError\u001b[0m: name 'pd' is not defined" + ] + } + ], + "source": [ + "admissions = pd.read_csv('../Admission_Predict.csv')\n", + "print(admissions.head())" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "b8fae2e3-fdeb-4c6b-897b-4009a2f0f2c7", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "7b0809db-f166-4e87-87bb-83d9ca798081", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " Serial No. GRE Score TOEFL Score University Rating SOP LOR CGPA \\\n", + "0 1 337 118 4 4.5 4.5 9.65 \n", + "1 2 316 104 3 3.0 3.5 8.00 \n", + "2 3 322 110 3 3.5 2.5 8.67 \n", + "3 4 314 103 2 2.0 3.0 8.21 \n", + "4 5 330 115 5 4.5 3.0 9.34 \n", + "\n", + " Research Chance of Admit \n", + "0 1 0.92 \n", + "1 1 0.72 \n", + "2 1 0.80 \n", + "3 0 0.65 \n", + "4 1 0.90 \n" + ] + } + ], + "source": [ + "admissions = pd.read_csv('../Admission_Predict.csv')\n", + "print(admissions.head())" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "9244a59c-5bc3-4641-81ec-e1a9e6b24a5e", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Serial No. 0\n", + "GRE Score 0\n", + "TOEFL Score 0\n", + "University Rating 0\n", + "SOP 0\n", + "LOR 0\n", + "CGPA 0\n", + "Research 0\n", + "Chance of Admit 0\n", + "dtype: int64\n" + ] + } + ], + "source": [ + "missing_data = admissions.isnull().sum()\n", + "print(missing_data)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "2afe8525-fa7c-4a57-90bb-d03a66ba151c", + "metadata": {}, + "outputs": [], + "source": [ + "admissions.set_index('Serial No.', drop=False, inplace=True)\n", + "print(admissions.head())\n", + "\n", + "unique_combinations = admissions.duplicated(subset=['GRE Score', 'CGPA']).sum()\n", + "if unique_combinations == 0:\n", + " print(\"\\nLa combinación de GRE Score y CGPA identifica de manera única cada fila.\")\n", + "else:\n", + " print(\"\\nHay filas duplicadas en la combinación de GRE Score y CGPA.\")" + ] + } + ], + "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": 5 +} From abf2ea80bf21284db4a6c5e34f1884b142d967e3 Mon Sep 17 00:00:00 2001 From: Alvarito-hash Date: Sat, 25 Oct 2025 18:41:04 +0200 Subject: [PATCH 8/8] Add files via upload --- Lab2_Week4.ipynb | 173 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 Lab2_Week4.ipynb diff --git a/Lab2_Week4.ipynb b/Lab2_Week4.ipynb new file mode 100644 index 00000000..3d735eab --- /dev/null +++ b/Lab2_Week4.ipynb @@ -0,0 +1,173 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "id": "50dcd935-1bbb-4e24-9014-7e55f41e52cf", + "metadata": {}, + "outputs": [], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "c48aa604-f138-4c6f-ae47-6dc9b22b3113", + "metadata": {}, + "outputs": [], + "source": [ + "df1 = pd.DataFrame({'A': ['a'+str(x) for x in range(3)],\n", + " 'B': ['b'+str(x) for x in range(3)],\n", + " 'C': ['c'+str(x) for x in range(3)]},\n", + " index=[0, 1, 2])\n", + "\n", + "df2 = pd.DataFrame({'A': ['a'+str(x) for x in range(3, 6)],\n", + " 'B': ['b'+str(x) for x in range(3, 6)],\n", + " 'C': ['c'+str(x) for x in range(3, 6)]},\n", + " index=[3, 4, 5]) \n", + "\n", + "df3 = pd.DataFrame({'D': ['d'+str(x) for x in range(3)],\n", + " 'E': ['e'+str(x) for x in range(3)],\n", + " 'F': ['f'+str(x) for x in range(3)]},\n", + " index=[0, 1, 2]) \n", + "\n", + "df4 = pd.DataFrame({'D': ['d'+str(x) for x in range(3, 6)],\n", + " 'E': ['e'+str(x) for x in range(3, 6)],\n", + " 'F': ['f'+str(x) for x in range(3, 6)]},\n", + " index=[3, 4, 5]) \n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "id": "cf96e993-e150-4be6-8b21-0d84dcaae546", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Concatenación de df1 y df2:\n", + " A B C\n", + "0 a0 b0 c0\n", + "1 a1 b1 c1\n", + "2 a2 b2 c2\n", + "3 a3 b3 c3\n", + "4 a4 b4 c4\n", + "5 a5 b5 c5 \n", + "\n", + "Concatenación de df3 y df4:\n", + " D E F\n", + "0 d0 e0 f0\n", + "1 d1 e1 f1\n", + "2 d2 e2 f2\n", + "3 d3 e3 f3\n", + "4 d4 e4 f4\n", + "5 d5 e5 f5\n" + ] + } + ], + "source": [ + "concat_df1_df2 = pd.concat([df1, df2])\n", + "print(\"Concatenación de df1 y df2:\\n\", concat_df1_df2, \"\\n\")\n", + "\n", + "concat_df3_df4 = pd.concat([df3, df4])\n", + "print(\"Concatenación de df3 y df4:\\n\", concat_df3_df4)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "ac21524b-3541-4352-9eab-c7d37494e015", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Concatenación de df1, df2, df3 y df4:\n", + " A B C D E F\n", + "0 a0 b0 c0 NaN NaN NaN\n", + "1 a1 b1 c1 NaN NaN NaN\n", + "2 a2 b2 c2 NaN NaN NaN\n", + "3 a3 b3 c3 NaN NaN NaN\n", + "4 a4 b4 c4 NaN NaN NaN\n", + "5 a5 b5 c5 NaN NaN NaN\n", + "0 NaN NaN NaN d0 e0 f0\n", + "1 NaN NaN NaN d1 e1 f1\n", + "2 NaN NaN NaN d2 e2 f2\n", + "3 NaN NaN NaN d3 e3 f3\n", + "4 NaN NaN NaN d4 e4 f4\n", + "5 NaN NaN NaN d5 e5 f5\n" + ] + } + ], + "source": [ + "concat_all = pd.concat([df1, df2, df3, df4], sort=False)\n", + "print(\"Concatenación de df1, df2, df3 y df4:\\n\", concat_all)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "id": "84efa559-0565-4156-8f20-8dac8ed3816d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Concatenación con ignore_index=True:\n", + " A B C D E F\n", + "0 a0 b0 c0 NaN NaN NaN\n", + "1 a1 b1 c1 NaN NaN NaN\n", + "2 a2 b2 c2 NaN NaN NaN\n", + "3 a3 b3 c3 NaN NaN NaN\n", + "4 a4 b4 c4 NaN NaN NaN\n", + "5 a5 b5 c5 NaN NaN NaN\n", + "6 NaN NaN NaN d0 e0 f0\n", + "7 NaN NaN NaN d1 e1 f1\n", + "8 NaN NaN NaN d2 e2 f2\n", + "9 NaN NaN NaN d3 e3 f3\n", + "10 NaN NaN NaN d4 e4 f4\n", + "11 NaN NaN NaN d5 e5 f5\n" + ] + } + ], + "source": [ + "concat_all_ignore = pd.concat([df1, df2, df3, df4], ignore_index=True, sort=False)\n", + "print(\"Concatenación con ignore_index=True:\\n\", concat_all_ignore)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a76828c8-2094-414d-91b6-598f3770bd73", + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "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": 5 +}