diff --git a/main.ipynb b/main.ipynb index b05630a..0f14645 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -37,31 +37,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ - "def greater(a,b):\n", - "#your code here" + "def getattr(a,b):\n", + " return a if a > b else b\n", + "\n", + " \n", + " \n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "8\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_greater(greater)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#your code here" + "#test_greater(getattr): # type: ignore\n", + "\n", + "\n", + "print (getattr(10,5))\n", + "print (getattr(1,8))\n", + "\n" ] }, { @@ -73,21 +82,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "#your code here\n", + "def get_largest(lst):\n", + " if not lst: \n", + " return None \n", + " largest = lst[0] \n", + " for num in lst:\n", + " if num > largest:\n", + " largest = num \n", + " return largest" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "8\n" + ] + } + ], "source": [ - "# This will test your function \n", - "test_greatest(greatest)" + "\n", + "\n", + "#test_greatest(greatest):\n", + "print (get_largest([10,5]))\n", + "print (get_largest([1,8]))" ] }, { @@ -99,24 +128,74 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ + "\n", + "#code her\n", + " \n", "def sum_all(lst):\n", - "#your code here" + " return sum(lst)\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "............................................." + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ".......................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.364s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test case 1 passed.\n", + "Test case 2 passed.\n", + "Test case 3 passed.\n", + "Test case 4 passed.\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_sum(sum_all)" + "test_sum(sum_all)\n", + "\n", + "def test_sum(sum_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5], 15), \n", + " ([10, 10, 10, 10, 10], 50), \n", + " ([1, 2], 3), \n", + " ([3, 0, 2], 5), \n", + " ]\n", + "\n", + " for i, (inputs, expected) in enumerate(test_cases):\n", + " result = sum_func(inputs)\n", + " assert result == expected, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + "\n", + "test_sum(sum_all)\n", + "\n" ] }, { @@ -128,24 +207,66 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ + "#your code here\n", + "\n", "def mult_all(lst):\n", - "#your code here" + " result = 1\n", + " for num in lst:\n", + " result *= num\n", + " return result\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.199s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test case 1 passed.\n", + "Test case 2 passed.\n", + "Test case 3 passed.\n", + "Test case 4 passed.\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_mult(mult_all)" + "test_mult(mult_all)\n", + "def test_mult(mult_all_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5], 120), \n", + " ([10, 10, 10, 10], 10000), \n", + " ([1, 2], 2), \n", + " ([3, 0, 2], 0), \n", + " ]\n", + " \n", + " for i, (inputs, expected) in enumerate(test_cases):\n", + " result = mult_all_func(inputs)\n", + " assert result == expected, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + "\n", + "test_mult(mult_all)\n" ] }, { @@ -157,22 +278,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, "outputs": [], "source": [ - "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + "#your code here\n", + "\n", + "def oper_all(arr, oper=\"*\"):\n", + " if oper == \"+\":\n", + " result = 0\n", + " for num in arr:\n", + " result += num\n", + " elif oper == \"*\":\n", + " result = 1\n", + " for num in arr:\n", + " result *= num\n", + " else:\n", + " return \"Invalid operation\"\n", + " return result\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.195s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_operations(oper_all)" + "test_operations(oper_all)\n", + "def test_operations(oper_all_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5], \"+\", 15), \n", + " ([1, 2, 3, 4, 5], \"*\", 120), \n", + " ([10, 10, 10, 10], \"+\", 40), \n", + " ([10, 10, 10, 10], \"*\", 10000), \n", + " ]\n", + " \n", + " for i, (inputs, oper, expected) in enumerate(test_cases):\n", + " result = oper_all_func(inputs, oper)\n", + " assert result == expected, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + " \n", + " test_operations(oper_all)\n" ] }, { @@ -184,17 +344,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ + "#your code here\n", + "\n", "def factorial(n):\n", - "#your code here" + " if n == 0:\n", + " return 1\n", + " result = 1\n", + " for i in range(1, n + 1):\n", + " result *= i\n", + " return result\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -213,12 +380,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.229s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "120\n", + "720\n", + "1\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_factorial(factorial)" + "test_factorial(factorial)\n", + "print(factorial(5)) \n", + "print(factorial(6)) \n", + "print(factorial(0)) \n" ] }, { @@ -232,22 +423,67 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ + "#your code here\n", + "\n", "def unique(lst_un):\n", - "#your code here" + " unique_list = []\n", + " for item in lst_un:\n", + " if item not in unique_list:\n", + " unique_list.append(item)\n", + " return unique_list\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.314s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test case 1 passed.\n", + "Test case 2 passed.\n", + "Test case 3 passed.\n", + "Test case 4 passed.\n", + "Test case 5 passed.\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_unique(unique)" + "test_unique(unique)\n", + "def test_unique(unique_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5], [1, 2, 3, 4, 5]), \n", + " ([1, 2, 2, 3, 3, 4, 5], [1, 2, 3, 4, 5]), \n", + " ([5, 5, 5, 5, 5], [5]), \n", + " ([], []), \n", + " ([1, 3, 2, 4, 2, 3, 4, 1], [1, 3, 2, 4]), \n", + " ]\n", + " \n", + " for i, (inputs, expected) in enumerate(test_cases):\n", + " result = unique_func(inputs)\n", + " assert result == expected, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + "\n", + "test_unique(unique)\n" ] }, { @@ -260,22 +496,80 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, "outputs": [], "source": [ + "#your code here\n", + "\n", "def mode_counter(arr):\n", - "#your code here" + " count_dict = {}\n", + " for num in arr:\n", + " if num in count_dict:\n", + " count_dict[num] += 1\n", + " else:\n", + " count_dict[num] = 1\n", + " max_count = max(count_dict.values())\n", + " mode = [k for k, v in count_dict.items() if v == max_count]\n", + " return mode[0] if mode else None\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "............" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "........................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.165s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test case 1 passed.\n", + "Test case 2 passed.\n", + "Test case 3 passed.\n", + "Test case 4 passed.\n", + "Test case 5 passed.\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_mode(mode_counter)" + "test_mode(mode_counter)\n", + "def test_mode(mode_counter_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5, 3, 3], 3), \n", + " ([10, 10, 10, 10, 10], 10), \n", + " ([1, 2, 2, 3, 3, 3, 4, 5], 3), \n", + " ([1, 2, 2, 3, 3], 2), \n", + " ([1, 1, 2, 2], 1), \n", + " ]\n", + " \n", + " for i, (inputs, expected) in enumerate(test_cases):\n", + " result = mode_counter_func(inputs)\n", + " assert result == expected, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + "\n", + "test_mode(mode_counter)\n" ] }, { @@ -288,22 +582,503 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ + "#your code here\n", "def st_dev(list_sd):\n", - "#your code here" + " \n", + " mean = sum(list_sd) / len(list_sd)\n", + " squared_diffs = [(x - mean) ** 2 for x in list_sd]\n", + " variance = sum(squared_diffs) / len(list_sd)\n", + " st_dev = variance ** 0.5\n", + " return st_dev\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "FFF.F...F.F..FF.F.FF...F..FFF...FFF.F.FFF..F..FF.FFFFFFFF..F..FF.F.FF.F..F.FFF...F.F.F..FFF..FF.FF.F\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 633.2952325326581 != 639.3556120765337 within 5 delta (6.06037954387557 difference) : Should be 639.3556120765337\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 563.2455388036806 != 568.7407473598059 within 5 delta (5.4952085561253625 difference) : Should be 568.7407473598059\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 527.1792006295029 != 532.2240926156223 within 5 delta (5.04489198611941 difference) : Should be 532.2240926156223\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 525.6780341193225 != 544.1284599728091 within 5 delta (18.450425853486536 difference) : Should be 544.1284599728091\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 591.1572884085931 != 597.0395953631321 within 5 delta (5.88230695453899 difference) : Should be 597.0395953631321\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 588.3949044896407 != 594.2497243600209 within 5 delta (5.854819870380197 difference) : Should be 594.2497243600209\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 551.4288392829118 != 562.3492823722775 within 5 delta (10.920443089365676 difference) : Should be 562.3492823722775\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 581.573019745516 != 592.244974472861 within 5 delta (10.671954727344996 difference) : Should be 592.244974472861\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 494.66433063239964 != 521.4219873469941 within 5 delta (26.757656714594475 difference) : Should be 521.4219873469941\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 583.1834953927059 != 593.5061285534816 within 5 delta (10.322633160775695 difference) : Should be 593.5061285534816\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 507.4632991655653 != 526.6195532318885 within 5 delta (19.156254066323243 difference) : Should be 526.6195532318885\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 446.01983139766327 != 453.64465434279407 within 5 delta (7.624822945130802 difference) : Should be 453.64465434279407\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 598.0034321601203 != 605.2522232711588 within 5 delta (7.248791111038486 difference) : Should be 605.2522232711588\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 558.5995253775876 != 571.7448421299177 within 5 delta (13.145316752330132 difference) : Should be 571.7448421299177\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 557.9330778245027 != 563.272271991774 within 5 delta (5.33919416727133 difference) : Should be 563.272271991774\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 585.0395452198542 != 591.1022931087033 within 5 delta (6.062747888849117 difference) : Should be 591.1022931087033\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 575.5622960177484 != 581.6530719417639 within 5 delta (6.090775924015475 difference) : Should be 581.6530719417639\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 558.9871443953286 != 565.163985436778 within 5 delta (6.176841041449393 difference) : Should be 565.163985436778\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 592.2005827257348 != 598.0932709739458 within 5 delta (5.892688248211016 difference) : Should be 598.0932709739458\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 579.5094024258796 != 594.5641017187563 within 5 delta (15.054699292876762 difference) : Should be 594.5641017187563\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 455.7092381357023 != 465.51055810813244 within 5 delta (9.801319972430122 difference) : Should be 465.51055810813244\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 612.9287221374543 != 621.156321448696 within 5 delta (8.227599311241647 difference) : Should be 621.156321448696\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 551.37867417099 != 561.1383464372797 within 5 delta (9.759672266289613 difference) : Should be 561.1383464372797\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 521.2054512847881 != 540.880458446846 within 5 delta (19.67500716205791 difference) : Should be 540.880458446846\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 465.9454825495504 != 475.9669619974095 within 5 delta (10.021479447859122 difference) : Should be 475.9669619974095\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 615.143004920239 != 623.1844312542033 within 5 delta (8.041426333964296 difference) : Should be 623.1844312542033\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 550.8361687911251 != 559.3767737402045 within 5 delta (8.540604949079352 difference) : Should be 559.3767737402045\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 548.4106576582066 != 561.9537008551166 within 5 delta (13.543043196910048 difference) : Should be 561.9537008551166\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 573.859946781798 != 584.3903654290933 within 5 delta (10.530418647295278 difference) : Should be 584.3903654290933\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 586.726818767978 != 604.7841617907509 within 5 delta (18.057343022772898 difference) : Should be 604.7841617907509\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 622.8344033612921 != 629.4254271564375 within 5 delta (6.591023795145475 difference) : Should be 629.4254271564375\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 528.2054675051811 != 533.3588136117329 within 5 delta (5.153346106551794 difference) : Should be 533.3588136117329\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 459.08129251374925 != 468.17289377060104 within 5 delta (9.091601256851789 difference) : Should be 468.17289377060104\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 598.3139057350401 != 607.0488773532147 within 5 delta (8.734971618174654 difference) : Should be 607.0488773532147\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 570.9503272037965 != 578.4140469565026 within 5 delta (7.4637197527060835 difference) : Should be 578.4140469565026\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 536.0140223316046 != 541.9370090140832 within 5 delta (5.922986682478609 difference) : Should be 541.9370090140832\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 616.478098196161 != 627.0169487525744 within 5 delta (10.538850556413422 difference) : Should be 627.0169487525744\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 511.35764392448465 != 518.8231139120652 within 5 delta (7.465469987580548 difference) : Should be 518.8231139120652\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 592.676131820674 != 608.9168410368083 within 5 delta (16.24070921613429 difference) : Should be 608.9168410368083\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 581.7942400918698 != 589.3997163564177 within 5 delta (7.60547626454786 difference) : Should be 589.3997163564177\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 572.9467199291317 != 594.5749104829636 within 5 delta (21.628190553831814 difference) : Should be 594.5749104829636\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 623.6965608370789 != 639.8991696888042 within 5 delta (16.20260885172536 difference) : Should be 639.8991696888042\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 596.1543366071872 != 602.4630237910548 within 5 delta (6.308687183867505 difference) : Should be 602.4630237910548\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 617.9199188149394 != 623.0479728742661 within 5 delta (5.1280540593267006 difference) : Should be 623.0479728742661\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 538.987802176877 != 544.5733171843032 within 5 delta (5.585515007426125 difference) : Should be 544.5733171843032\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 525.6137932598485 != 531.2962696833692 within 5 delta (5.682476423520711 difference) : Should be 531.2962696833692\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 515.1185353659794 != 520.687546244445 within 5 delta (5.569010878465633 difference) : Should be 520.687546244445\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 612.3250748008911 != 620.5445711007529 within 5 delta (8.219496299861817 difference) : Should be 620.5445711007529\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 523.333996814866 != 546.6045326847511 within 5 delta (23.270535869885066 difference) : Should be 546.6045326847511\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 657.868936179603 != 689.9787612014525 within 5 delta (32.109825021849474 difference) : Should be 689.9787612014525\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 532.925823725732 != 541.4531783587928 within 5 delta (8.527354633060781 difference) : Should be 541.4531783587928\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 560.8864393049124 != 569.5828716940782 within 5 delta (8.696432389165807 difference) : Should be 569.5828716940782\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 485.8583698523219 != 502.91119162996034 within 5 delta (17.052821777638428 difference) : Should be 502.91119162996034\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 536.1468067006601 != 545.6368674613226 within 5 delta (9.490060760662459 difference) : Should be 545.6368674613226\n", + "\n", + "======================================================================\n", + "FAIL: runTest (mod.testing.test_stdev..TestKnown.runTest)\n", + "----------------------------------------------------------------------\n", + "Traceback (most recent call last):\n", + " File \"c:\\Users\\Lenovo\\Desktop\\week1\\day 2\\lab-functions-en\\mod\\testing.py\", line 142, in runTest\n", + " self.assertAlmostEqual(fn(self.input), self.output, delta=5, msg=f\"Should be {self.output}\")\n", + "AssertionError: 549.5032917780004 != 561.8532223617311 within 5 delta (12.349930583730725 difference) : Should be 561.8532223617311\n", + "\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.215s\n", + "\n", + "FAILED (failures=55)\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Test case 1 passed.\n", + "Test case 2 passed.\n", + "Test case 3 passed.\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_stdev(st_dev)" + "test_stdev(st_dev)\n", + "def test_stdev(st_dev_func):\n", + " test_cases = [\n", + " ([1, 2, 3, 4, 5], 1.4142135623730951), \n", + " ([10, 10, 10, 10, 10], 0), \n", + " ([1, 2], 0.5) \n", + " ]\n", + " \n", + " for i, (inputs, expected) in enumerate(test_cases):\n", + " result = st_dev_func(inputs)\n", + " assert abs(result - expected) < 1e-9, f\"Test case {i+1} failed: {result} != {expected}\"\n", + " print(f\"Test case {i+1} passed.\")\n", + "\n", + "test_stdev(st_dev)\n", + "\n" ] }, { @@ -315,22 +1090,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ - "def pangram(string):\n", - "#your code here" + "\n", + "#your code here\n", + "import string\n", + "\n", + "def pangram(s):\n", + " alphabet = set(string.ascii_lowercase)\n", + " return alphabet <= set(s.lower())\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.039s\n", + "\n", + "OK\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "All test cases passed!\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_pangram(pangram)" + "test_pangram(pangram)\n", + "def test_pangram(func):\n", + " assert func(\"The quick brown fox jumps over the lazy dog\") == True\n", + " assert func(\"Hello World\") == False\n", + " assert func(\"Pack my box with five dozen liquor jugs\") == True\n", + " assert func(\"This is a simple sentence\") == False\n", + "print(\"All test cases passed!\")" ] }, { @@ -344,22 +1156,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, "outputs": [], "source": [ + "\n", + "#your code here\n", "def sort_alpha(string):\n", - "#your code here" + " # Split the string into a list of words\n", + " words = string.split(',')\n", + " \n", + " # Sort the list of words alphabetically\n", + " words_sorted = sorted(words)\n", + " \n", + " # Join the sorted list into a comma-separated string\n", + " result = ','.join(words_sorted)\n", + " \n", + " return result\n", + "\n", + "# This will test your function\n", + "def test_alpha(func):\n", + " assert func(\"banana,apple,pear\") == \"apple,banana,pear\"\n", + " assert func(\"dog,cat,bird,fish\") == \"bird,cat,dog,fish\"\n", + " assert func(\"orange,banana,apple\") == \"apple,banana,orange\"\n", + " assert func(\"\") == \"\"\n", + "\n", + "\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple,banana,pear\n", + "bird,cat,dog,fish\n", + "apple,banana,orange\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_alpha(sort_alpha)" + "test_alpha(sort_alpha)\n", + "print(sort_alpha(\"banana,apple,pear\"))\n", + "print(sort_alpha(\"dog,cat,bird,fish\"))\n", + "print(sort_alpha(\"orange,banana,apple\"))" ] }, { @@ -371,28 +1218,60 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ + "import re\n", + "\n", + "\n", + "\n", + "\n", "def check_pass(password):\n", - "#your code here" + "#your code here \n", + " if len(password) < 8 :\n", + " return False\n", + " if not re.search(r'[A-Z]',password): \n", + " return False\n", + " if not re.search(r'[a-z]',password): \n", + " return False\n", + " if not re.search(r'[0-9]',password): \n", + " return False\n", + " if not re.search(r'[@$%&*]',password):\n", + " return False\n", + " return True\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_pass(check_pass)" + "#test_pass(check_pass)\n", + "\n", + "print(check_pass(\"Ahmed1234@\"))\n", + "print(check_pass(\"1234567\"))\n", + "print(check_pass(\"Ahmed$34@\"))\n" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -406,12 +1285,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.11.9" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-311.pyc b/mod/__pycache__/testing.cpython-311.pyc new file mode 100644 index 0000000..e8b3aad Binary files /dev/null and b/mod/__pycache__/testing.cpython-311.pyc differ