diff --git a/main.ipynb b/main.ipynb index b05630a..453e7e2 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -37,31 +37,101 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", - "#your code here" + "#your code here\n", + " if a > b:\n", + " return a \n", + "\n", + " else:\n", + " return b\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "8" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# This will test your function \n", - "test_greater(greater)" + "greater(5,8)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "24049723" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greater(727597, 24049723)" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2346234" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#your code here" + "greater (2346234, 234723)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function greater works\n" + ] + } + ], + "source": [ + "# This will test your function \n", + "def test_greater(greater):\n", + " assert greater(2346234, 234723) == 2346234\n", + " assert greater( 727597, 24049723) == 24049723\n", + " assert greater (5, 8) == 8\n", + " print (\"Function greater works\")\n", + "\n", + "test_greater(greater)" ] }, { @@ -73,21 +143,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "#your code here\n", + "def largest_e(lst):\n", + "#your code here\n", + " if not list:\n", + " return None\n", + " \n", + " x = lst[0]\n", + " for num in lst:\n", + " if num > x :\n", + " x = num\n", + " return x\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 73, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# This will test your function \n", - "test_greatest(greatest)" + "largest_e([3, 5, 6])" ] }, { @@ -101,21 +191,64 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "15\n" + ] + } + ], "source": [ "def sum_all(lst):\n", - "#your code here" + "#your code here\n", + " sum_result = 0\n", + "\n", + " for num in lst:\n", + " sum_result += num\n", + " return sum_result\n", + "print(sum_all([1, 2, 3, 4, 5]))\n" ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "scrolled": true - }, - "outputs": [], + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "755474" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# This will test your function \n", + "sum_all([1, 2, 686698, 68768, 5])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function sum_all works\n" + ] + } + ], + "source": [ + "def test_sum(sum_all):\n", + " assert sum_all([1, 2, 3, 4, 5]) == 15\n", + " assert sum_all([1, 2, 686698, 68768, 5]) == 755474\n", + " print(\"Function sum_all works\")\n", "test_sum(sum_all)" ] }, @@ -130,10 +263,45 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "120\n" + ] + } + ], "source": [ "def mult_all(lst):\n", - "#your code here" + "#your code here\n", + " mult_result = 1\n", + " for num in lst:\n", + " mult_result *= num\n", + " return mult_result\n", + "\n", + "print(mult_all([1, 2, 3, 4, 5]))\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1600" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mult_all([1, 2, 40, 4, 5])" ] }, { @@ -142,9 +310,23 @@ "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function mult_all works\n" + ] + } + ], "source": [ "# This will test your function \n", + "\n", + "def test_mult(mult_all):\n", + " assert mult_all([1, 2, 3, 4, 5]) == 120\n", + " assert mult_all([1, 2, 40, 4, 5]) == 1600\n", + " print(\"Function mult_all works\")\n", + "\n", "test_mult(mult_all)" ] }, @@ -157,21 +339,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ - "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + "def oper_all(arr, oper):\n", + " if oper == \"+\":\n", + " result = sum (arr)\n", + " print(\" The result of the sum is\", {result})\n", + " return result\n", + " elif oper == \"*\":\n", + " result = 1\n", + " for n in arr:\n", + " result *= n\n", + " print(\" The result of the multiplication is\", {result} )\n", + " return result\n", + "\n", + " else:\n", + " print (\"error\")\n", + " result = None\n", + "\n", + "\n", + " \n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " The result of the sum is {10}\n", + " The result of the multiplication is {24}\n", + "Function oper_all works\n" + ] + } + ], "source": [ "# This will test your function \n", + "def test_operations(oper):\n", + " assert oper_all([1, 2, 3, 4], \"+\") == 10\n", + " assert oper_all([1, 2, 3, 4], \"*\") == 24\n", + " print(\"Function oper_all works\")\n", + "\n", "test_operations(oper_all)" ] }, @@ -189,7 +403,52 @@ "outputs": [], "source": [ "def factorial(n):\n", - "#your code here" + " if n < 0:\n", + " raise ValueError(\"Error\")\n", + " product = 1\n", + " for i in range(1, n + 1):\n", + " product *= i\n", + " return product \n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "24" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factorial(4)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3628800" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "factorial(10)" ] }, { @@ -215,10 +474,24 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function factorial works\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_factorial(factorial)" + "\n", + "def test_mult(mult_all):\n", + " assert factorial(4) == 24\n", + " assert factorial(10) == 3628800\n", + " print(\"Function factorial works\")\n", + "\n", + "test_mult(factorial)" ] }, { @@ -234,19 +507,89 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5]\n" + ] + } + ], "source": [ - "def unique(lst_un):\n", - "#your code here" + "def unique(lst):\n", + "\n", + " unique_list =[]\n", + " for num in lst:\n", + " if num not in unique_list:\n", + " unique_list.append(num)\n", + " return unique_list\n", + "\n", + "print(unique([1, 2, 3, 4, 5, 5]))\n", + "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 45, 5]" + ] + }, + "execution_count": 86, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique([1, 2, 3, 45, 1, 1, 5, 5])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 88, 45, 5]" + ] + }, + "execution_count": 87, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "unique([1, 88, 88, 45, 1, 1, 5, 5])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function unique works\n" + ] + } + ], "source": [ "# This will test your function \n", + "\n", + "def test_unique(unique):\n", + " assert unique([1, 2, 3, 45, 1, 1, 5, 5]) == [1, 2, 3, 45, 5]\n", + " assert unique([1, 88, 88, 45, 1, 1, 5, 5]) == [1, 88, 45, 5]\n", + " print(\"Function unique works\")\n", + "\n", "test_unique(unique)" ] }, @@ -264,18 +607,68 @@ "metadata": {}, "outputs": [], "source": [ - "def mode_counter(arr):\n", - "#your code here" + "def mode_counter(lst):\n", + " most = max(set(lst), key=lambda x: sum(1 for i in lst if i == x))\n", + " return [most]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2]\n" + ] + } + ], + "source": [ + "numbers = [1, 2, 3, 2, 4, 2, 5]\n", + "print(mode_counter(numbers)) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6]\n" + ] + } + ], + "source": [ + "numbers = [1, 2, 3, 2,6,6,6,6,6,6, 4, 2, 5]\n", + "print(mode_counter(numbers)) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function mode_counter works\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_mode(mode_counter)" + "def test_mode_counter(mode_counter):\n", + " assert mode_counter([1, 2, 3, 2, 4, 2, 5]) == [2]\n", + " assert mode_counter([1, 2, 3, 2,6,6,6,6,6,6, 4, 2, 5]) == [6]\n", + " print(\"Function mode_counter works\")\n", + "\n", + "test_mode_counter(mode_counter)" ] }, { @@ -293,17 +686,73 @@ "outputs": [], "source": [ "def st_dev(list_sd):\n", - "#your code here" + "#your code here\n", + "\n", + " mean = sum(list_sd) / len(list_sd)\n", + "\n", + " variance = sum(( x-mean)**2 for x in list_sd)/ len(list_sd)\n", + " st_dev = variance ** 0.5\n", + " \n", + " return [st_dev]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[105.7745243430572]\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_stdev(st_dev)" + "list_sd = [4, 46, 345, 4, 63, 4, 62, 56 ]\n", + "print(st_dev(list_sd))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1161801.997261523]\n" + ] + } + ], + "source": [ + "list_sd = [4, 46, 345, 4, 63, 4, 3463, 4363463, 4535, 34543, 223, 62, 56]\n", + "print(st_dev(list_sd))\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function st_dev works\n" + ] + } + ], + "source": [ + "def test_st_dev(st_dev):\n", + " assert st_dev([4, 46, 345, 4, 63, 4, 62, 56]) == [105.7745243430572]\n", + " assert st_dev([4, 46, 345, 4, 63, 4, 3463, 4363463, 4535, 34543, 223, 62, 56]) == [1161801.997261523]\n", + " print(\"Function st_dev works\")\n", + "\n", + "test_st_dev(st_dev)" ] }, { @@ -317,10 +766,22 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']\n" + ] + } + ], "source": [ - "def pangram(string):\n", - "#your code here" + "\n", + "#your code here\n", + "import string\n", + "\n", + "english_alphabet = list(string.ascii_uppercase)\n", + "print(english_alphabet)" ] }, { @@ -329,8 +790,86 @@ "metadata": {}, "outputs": [], "source": [ - "# This will test your function \n", - "test_pangram(pangram)" + "import string\n", + "\n", + "def pangram(lista):\n", + " english_alphabet = string.ascii_lowercase\n", + " counter = 0 \n", + " lista = lista.lower()\n", + "\n", + " for letter in english_alphabet:\n", + " if letter in lista:\n", + " counter += 1\n", + "\n", + " else:\n", + " return(\"No pangram\") \n", + " \n", + " if counter == 26:\n", + " return(\"It is pangram\")\n", + "\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'It is pangram'" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pangram (\"The quick brown fox jumps over the lazy dog\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'No pangram'" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pangram (\"Thedgsadgas quicown fox ffsdfafasjumps over fwefwefwethe lazy dog\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function pangram works\n" + ] + } + ], + "source": [ + "def test_pangram():\n", + " assert pangram(\"The quick brown fox jumps over the lazy dog\") == \"It is pangram\"\n", + " assert pangram(\"Thedgsadgas quicown fox ffsdfafasjumps over fwefwefwethe lazy dog\") == \"No pangram\"\n", + " print(\"Function pangram works\")\n", + "\n", + "test_pangram()" ] }, { @@ -348,18 +887,75 @@ "metadata": {}, "outputs": [], "source": [ - "def sort_alpha(string):\n", - "#your code here" + "\n", + "#your code here\n", + "import string\n", + "\n", + "def sort_alpha(list):\n", + " return sorted(list)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['banana', 'kiwi', 'manzana', 'naranja']" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sort_alpha([\"naranja\", \"manzana\", \"banana\", \"kiwi\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['banana', 'kiwi', 'naranja', 'peach', 'watermelon']" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sort_alpha([\"naranja\", \"peach\", \"banana\", \"kiwi\", \"watermelon\"])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function sort_alpha works\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_alpha(sort_alpha)" + "def test_sort_alpha():\n", + " assert sort_alpha([\"naranja\", \"manzana\", \"banana\", \"kiwi\"]) == ['banana', 'kiwi', 'manzana', 'naranja']\n", + " assert sort_alpha([\"naranja\", \"peach\", \"banana\", \"kiwi\", \"watermelon\"]) == ['banana', 'kiwi', 'naranja', 'peach', 'watermelon']\n", + " print(\"Function sort_alpha works\")\n", + "\n", + "test_sort_alpha()" ] }, { @@ -371,28 +967,105 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, "outputs": [], "source": [ + "import string\n", + "\n", "def check_pass(password):\n", - "#your code here" + " if len(password) < 8:\n", + " return False\n", + "\n", + " counter_digit = 0\n", + " counter_lower = 0\n", + " counter_upper = 0\n", + " counter_punctuation = 0\n", + "\n", + " for character in password:\n", + " if character.isdigit():\n", + " counter_digit += 1\n", + " elif character.islower():\n", + " counter_lower += 1\n", + " elif character.isupper():\n", + " counter_upper += 1\n", + " elif character in string.punctuation:\n", + " counter_punctuation += 1\n", + "\n", + " if counter_digit == 0:\n", + " return False\n", + " if counter_lower == 0:\n", + " return False\n", + " if counter_upper == 0:\n", + " return False\n", + " if counter_punctuation == 0:\n", + " return False\n", + "\n", + " return True" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 89, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], "source": [ + "print(check_pass(\"789oizuiuizoi\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(check_pass(\"789o*zuI\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Function check_pass works\n" + ] + } + ], + "source": [ + "\n", "# This will test your function \n", - "test_pass(check_pass)" + "def test_pass(check_pass):\n", + " assert check_pass (\"789oizuiuizoi\") == False\n", + " assert check_pass(\"789o*zuI\") == True\n", + " print(\"Function check_pass works\")\n", + "\n", + "test_pass(check_pass) " ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -406,12 +1079,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.8" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-313.pyc b/mod/__pycache__/testing.cpython-313.pyc new file mode 100644 index 0000000..0d3d098 Binary files /dev/null and b/mod/__pycache__/testing.cpython-313.pyc differ