diff --git a/main.ipynb b/main.ipynb index b05630a..962783f 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -37,33 +37,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", - "#your code here" + "#your code here\n", + " if a > b:\n", + " return a\n", + " elif b > a:\n", + " return b\n", + " \n", + " \n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.097s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#your code here" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -73,18 +82,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "#your code here\n", + "def greatest(list):\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, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.124s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" @@ -99,21 +126,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "def sum_all(lst):\n", - "#your code here" + "#your code here\n", + " total = 0\n", + " for item in lst:\n", + " total = total + item\n", + " return total" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.165s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" @@ -128,21 +171,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "def mult_all(lst):\n", - "#your code here" + "#your code here\n", + " result = 1\n", + " for i in lst:\n", + " result *= i\n", + "\n", + " return result" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + ".................." + ] + }, + { + "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_mult(mult_all)" @@ -157,19 +224,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + "#your code here\n", + " if oper == \"+\":\n", + " return sum(arr)\n", + " \n", + " if oper == \"*\":\n", + " result = 1\n", + " for i in arr:\n", + " result *= i\n", + " return result\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.133s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -184,12 +273,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", - "#your code here" + "#your code here\n", + "\n", + " if n <= 0:\n", + " return 1\n", + " else:\n", + " local_factorial = n * factorial(n - 1)\n", + " return local_factorial" ] }, { @@ -213,9 +308,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.144s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -232,19 +339,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ "def unique(lst_un):\n", - "#your code here" + "#your code here\n", + " unique_list = []\n", + " \n", + " for i in lst_un:\n", + " if i not in unique_list:\n", + " unique_list.append(i)\n", + "\n", + " return unique_list\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.560s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -260,19 +386,47 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", - "#your code here" + "#your code here\n", + " mode = None\n", + " mode_count = 0\n", + "\n", + " for item in arr:\n", + " \n", + " count = 0\n", + " for other in arr:\n", + " if other == item:\n", + " count += 1\n", + "\n", + " \n", + " if count > mode_count:\n", + " mode_count = count\n", + " mode = item\n", + "\n", + " return mode\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.606s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" @@ -288,19 +442,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "def st_dev(list_sd):\n", - "#your code here" + "#your code here\n", + " # mean\n", + " total = 0\n", + " count = 0\n", + " for x in list_sd:\n", + " total += x\n", + " count += 1\n", + " if count == 0:\n", + " return 0.0 \n", + " mean = total / count\n", + "\n", + " # sum of squared deviations\n", + " ss = 0\n", + " for x in list_sd:\n", + " d = x - mean\n", + " ss += d * d\n", + "\n", + " # sample variance and stdev\n", + " if count == 1:\n", + " return 0.0\n", + " variance = ss / (count - 1)\n", + " return variance ** 0.5\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.208s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -315,19 +502,55 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "metadata": {}, "outputs": [], "source": [ "def pangram(string):\n", - "#your code here" + "#your code here\n", + " alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n", + " letters_found = []\n", + "\n", + " # converting to lowercase for comparison\n", + " for char in string:\n", + " if \"a\" <= char.lower() <= \"z\":\n", + " # checking if char already added\n", + " found = False\n", + " for l in letters_found:\n", + " if l == char.lower():\n", + " found = True\n", + " break\n", + " if not found:\n", + " letters_found.append(char.lower())\n", + "\n", + " # checking for the 26 letters\n", + " count = 0\n", + " for _ in letters_found:\n", + " count += 1\n", + "\n", + " if count == 26:\n", + " return True\n", + " else:\n", + " return False\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.046s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -344,19 +567,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ "def sort_alpha(string):\n", - "#your code here" + "#your code here\n", + "\n", + " # splitting the string by commas into a list\n", + " words = []\n", + " word = \"\"\n", + " for ch in string:\n", + " if ch != \",\":\n", + " word += ch\n", + " else:\n", + " words.append(word)\n", + " word = \"\"\n", + " words.append(word) # add the last word\n", + "\n", + " # sort\n", + " n = 0\n", + " for _ in words:\n", + " n += 1\n", + "\n", + " for i in range(n):\n", + " for j in range(0, n - i - 1):\n", + " if words[j] > words[j + 1]:\n", + " temp = words[j]\n", + " words[j] = words[j + 1]\n", + " words[j + 1] = temp\n", + "\n", + " # joinning back into a comma-separated string\n", + " result = \"\"\n", + " first = True\n", + " for w in words:\n", + " if not first:\n", + " result += \",\"\n", + " result += w\n", + " first = False\n", + "\n", + " return result\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.142s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -371,19 +640,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 69, "metadata": {}, "outputs": [], "source": [ "def check_pass(password):\n", - "#your code here" + "#your code here\n", + "\n", + " # Checking the length\n", + " length_ok = False\n", + " count = 0\n", + " for _ in password:\n", + " count += 1\n", + " if count >= 8:\n", + " length_ok = True\n", + "\n", + " # Checking for character types\n", + " has_lower = False\n", + " has_upper = False\n", + " has_digit = False\n", + " has_special = False\n", + "\n", + " for ch in password:\n", + " if 'a' <= ch <= 'z':\n", + " has_lower = True\n", + " elif 'A' <= ch <= 'Z':\n", + " has_upper = True\n", + " elif '0' <= ch <= '9':\n", + " has_digit = True\n", + " else:\n", + " has_special = True\n", + "\n", + " # Stong Password only if all are True\n", + " if length_ok and has_lower and has_upper and has_digit and has_special:\n", + " return True\n", + " else:\n", + " return False\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "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_pass(check_pass)" @@ -392,7 +703,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -406,12 +717,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.12.7" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-312.pyc b/mod/__pycache__/testing.cpython-312.pyc new file mode 100644 index 0000000..23dc913 Binary files /dev/null and b/mod/__pycache__/testing.cpython-312.pyc differ