diff --git a/main.ipynb b/main.ipynb index b05630a..b1b2b48 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -37,19 +37,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", - "#your code here" + " if a > b:\n", + " return a\n", + " elif b > a:\n", + " return b\n", + " else:\n", + " print(\"The numbers are equal!\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.234s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" @@ -59,9 +76,21 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "100" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#your code here" + "#selftest\n", + "greater(100,1)" ] }, { @@ -73,23 +102,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "#your code here\n", + "def greatest(lista):\n", + " largest_element = None\n", + " for element in lista:\n", + " if largest_element is None or largest_element < element:\n", + " largest_element = element\n", + " return largest_element\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.156s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" ] }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1502" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greatest(lista = [15, 110, 1502, 6, 58, 48])" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -99,26 +166,85 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "def sum_all(lst):\n", - "#your code here" + " sum = 0\n", + " for num in lst:\n", + " sum += num\n", + " return sum\n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.189s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1739" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest\n", + "sum_all(lst = [15, 110, 1502, 6, 58, 48])" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1739" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest with build-in function\n", + "lst = [15, 110, 1502, 6, 58, 48]\n", + "sum(lst)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -133,21 +259,57 @@ "outputs": [], "source": [ "def mult_all(lst):\n", - "#your code here" + " product = 1\n", + " for i in lst:\n", + " product = product * i\n", + " return product\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.204s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mult(mult_all)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "41397523200" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest\n", + "mult_all(lst)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -157,24 +319,72 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + " if oper == \"+\":\n", + " total = 0\n", + " for i in arr:\n", + " total += i\n", + " elif oper == \"*\":\n", + " total = 1\n", + " for i in arr:\n", + " total = total * i\n", + " return total\n", + " \n", + " \n", + "\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.269s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "601" + ] + }, + "execution_count": 46, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest\n", + "\n", + "listc = [110,51,58,6,325,51]\n", + "oper_all(listc, \"+\")" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -184,12 +394,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", - "#your code here" + " fact = 1\n", + " for x in range(1, n+1):\n", + " fact *= x\n", + " return fact\n", + "\n" ] }, { @@ -213,14 +427,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.198s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "720" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest \n", + "\n", + "factorial(6)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -232,24 +480,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ "def unique(lst_un):\n", - "#your code here" + " un_lst = []\n", + " for val in lst_un:\n", + " if val not in un_lst:\n", + " un_lst.append(val)\n", + " return un_lst\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.368s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[12, 15, 2, 5]" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest \n", + "\n", + "ran_lst = [12, 12, 12, 15, 15, 2, 5, 5]\n", + "\n", + "unique(ran_lst)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -260,24 +549,76 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", - "#your code here" + " freqs = {}\n", + " for x in arr:\n", + " if x not in freqs:\n", + " freqs[x] = 1\n", + " else:\n", + " freqs[x] += 1\n", + " mode = None\n", + " max_count = 0\n", + " for i in freqs:\n", + " if freqs[i] > max_count:\n", + " mode = i\n", + " max_count = freqs[i]\n", + " return mode\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "......." + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ".............................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.210s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12" + ] + }, + "execution_count": 62, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# selftest \n", + "mode_counter(ran_lst)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -288,19 +629,109 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, "outputs": [], "source": [ "def st_dev(list_sd):\n", - "#your code here" + " total = 0\n", + " sum = 0\n", + " for x in list_sd:\n", + " total += 1\n", + " sum += x\n", + "\n", + " mean = sum/total\n", + "\n", + " sum_sqr_dev = 0\n", + " for x in list_sd:\n", + " dev = x - mean\n", + " sum_sqr_dev += dev*dev\n", + "\n", + " var = sum_sqr_dev/(total - 1)\n", + " sd_dev = var ** 0.5\n", + "\n", + " return sd_dev\n", + "\n", + "\n", + "# Standard Deviation:\n", + "# 1. calculate mean = sum/total\n", + "# 2. substract mean from each data point, dev = x - mean\n", + "# 3. square deviation, (dev)^2\n", + "# 4. sum sqr dev, sum((dev)^2)\n", + "# 5. calculate variance, var = sum sqr dev / total\n", + "# 6. find square root, sqr root(var)\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "295.9241832331758" + ] + }, + "execution_count": 77, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#check wits build-in function: \n", + "\n", + "list_sd = [15, 44, 47, 48, 11, 532, 896, 51, 24, 145]\n", + "\n", + "stdev(list_sd)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "295.9241832331758" + ] + }, + "execution_count": 78, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest\n", + "\n", + "st_dev(list_sd)" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....." + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "...............................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.120s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -320,14 +751,185 @@ "outputs": [], "source": [ "def pangram(string):\n", - "#your code here" + " has_lower = False\n", + " #has_upper = False\n", + "\n", + " string = string.lower()\n", + "\n", + " for char in string:\n", + " if char == \"a\" and char == \"b\" and char == \"c\" and char == \"d\" and char == \"e\" and char == \"f\" and char == \"g\" and char == \"h\" and char == \"i\" and char == \"j\" and char == \"k\" and char == \"l\" and char == \"m\" and char == \"n\" and char == \"o\" and char == \"p\" and char == \"q\" and char == \"r\" and char == \"s\" and char == \"t\" and char == \"u\" and char == \"v\" and char == \"w\" and char == \"x\" and char == \"y\" and char == \"z\":\n", + " has_lower = True\n", + " #if char == \"A\" and char == \"B\" and char == \"C\" and char == \"D\" and char == \"E\" and char == \"F\" and char == \"G\" and char == \"H\" and char == \"I\" and char == \"J\" and char == \"K\" and char == \"L\" and char == \"M\" and char == \"N\" and char == \"O\" and char == \"P\" and char == \"Q\" and char == \"R\" and char == \"S\" and char == \"T\" and char == \"U\" and char == \"V\" and char == \"W\" and char == \"X\" and char == \"Y\" and char == \"Z\":\n", + " #has_upper = True\n", + "\n", + " if has_lower: #and has_upper:\n", + " return True \n", + " else:\n", + " return False \n", + " \n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 99, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "FFFFFFFFFFFFFFF..F...F....F...\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_pangram..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\black\\Documents\\Ironhack\\Week_1\\Day3\\lab-functions-en\\mod\\testing.py\", line 172, in runTest\n", + " self.assertEqual(fn(self.input), self.output, f\"Should be {self.output}\")\n", + "AssertionError: False != True : Should be True\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.068s\n", + "\n", + "FAILED (failures=18)\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -349,19 +951,79 @@ "outputs": [], "source": [ "def sort_alpha(string):\n", - "#your code here" + " sorted_lst = [\"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\", \"\",]\n", + " words = 0\n", + "\n", + " for char in string:\n", + " if char == \",\":\n", + " words += 1\n", + " else:\n", + " sorted_lst[words] = sorted_lst[words] + char\n", + "\n", + "\n", + " sorted_lst = sorted(sorted_lst)\n", + "\n", + " result = \"\"\n", + " first = True\n", + "\n", + " for word in sorted_lst:\n", + " if word != \"\":\n", + " if not first:\n", + " result = result + \",\"\n", + " result = result + word\n", + " first = False\n", + "\n", + " return result\n", + "\n", + "# need to fix, that first word is being integrated as well " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 126, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.204s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "' alpine, my, number, x,hello'" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest \n", + "\n", + "strg = \"hello, my, alpine, x, number\"\n", + "\n", + "sort_alpha(strg)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -376,23 +1038,79 @@ "outputs": [], "source": [ "def check_pass(password):\n", - "#your code here" + " length = 0\n", + " has_lower = False\n", + " has_upper = False\n", + " has_digit = False\n", + " has_spechar = False\n", + "\n", + " for char in password:\n", + " length += 1\n", + " if char == \"a\" or char == \"b\" or char == \"c\" or char == \"d\" or char == \"e\" or char == \"f\" or char == \"g\" or char == \"h\" or char == \"i\" or char == \"j\" or char == \"k\" or char == \"l\" or char == \"m\" or char == \"n\" or char == \"o\" or char == \"p\" or char == \"q\" or char == \"r\" or char == \"s\" or char == \"t\" or char == \"u\" or char == \"v\" or char == \"w\" or char == \"x\" or char == \"y\" or char == \"z\":\n", + " has_lower = True\n", + " if char == \"A\" or char == \"B\" or char == \"C\" or char == \"D\" or char == \"E\" or char == \"F\" or char == \"G\" or char == \"H\" or char == \"I\" or char == \"J\" or char == \"K\" or char == \"L\" or char == \"M\" or char == \"N\" or char == \"O\" or char == \"P\" or char == \"Q\" or char == \"R\" or char == \"S\" or char == \"T\" or char == \"U\" or char == \"V\" or char == \"W\" or char == \"X\" or char == \"Y\" or char == \"Z\":\n", + " has_upper = True\n", + " if char == \"0\" or char == \"1\" or char == \"2\" or char == \"3\" or char == \"4\" or char == \"5\" or char == \"6\" or char == \"7\" or char == \"8\" or char == \"9\":\n", + " has_digit = True\n", + " if char == \"!\" or char == \"@\" or char == \"#\" or char == \"$\" or char == \"%\" or char == \"?\" or char == \"&\" or char == \"(\" or char == \")\" or char == \"{\" or char == \"}\" or char == \"^\" or char == \"*\" or char == \"+\" or char == \"[\" or char == \"]\":\n", + " has_spechar = True\n", + "\n", + " if length >= 8 and has_lower and has_upper and has_digit and has_spechar:\n", + " return True \n", + " else:\n", + " return False \n", + "\n", + "\n", + "# comment: probably not working for all password cases, as the special characters list could be definietly longer" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.143s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 88, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#selftest\n", + "check_pass(\"hJI0[kdowßlS76\")" + ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Ironhack", "language": "python", "name": "python3" }, @@ -406,12 +1124,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.12.11" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-312.pyc b/mod/__pycache__/testing.cpython-312.pyc new file mode 100644 index 0000000..b5a9df0 Binary files /dev/null and b/mod/__pycache__/testing.cpython-312.pyc differ