diff --git a/main.ipynb b/main.ipynb index b05630a..aa4220e 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -37,19 +37,33 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", - "#your code here" + " if a > b:\n", + " return a\n", + " return b" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.200s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" @@ -57,11 +71,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#your code here" + "greater(3,2)" ] }, { @@ -73,18 +98,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "lst = [1,2,3]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], + "source": [ + "def greatest(lst):\n", + " largest = lst[0]\n", + " for i in lst:\n", + " if i > largest:\n", + " largest = i\n", + " return largest\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "greatest(lst)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.102s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" @@ -99,21 +171,61 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "def sum_all(lst):\n", - "#your code here" + " total = 0\n", + " for i in lst:\n", + " total += i\n", + " return total" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3]\n" + ] + } + ], + "source": [ + "sum_all(lst)\n", + "print(lst)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, "metadata": { "scrolled": true }, - "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_sum(sum_all)" @@ -128,21 +240,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def mult_all(lst):\n", - "#your code here" + " total = 1\n", + " for i in lst:\n", + " total *= i\n", + " return total" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": { "scrolled": true }, - "outputs": [], + "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_mult(mult_all)" @@ -157,19 +284,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + " if oper == \"*\":\n", + " result = 1\n", + " for i in arr:\n", + " result *= i\n", + " return result\n", + " elif oper == \"+\":\n", + " result = 0\n", + " for i in arr:\n", + " result += i\n", + " return result\n", + " else:\n", + " return None" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.135s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -184,12 +334,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", - "#your code here" + " result = 1\n", + " for i in range(n):\n", + " result = result*(1+i)\n", + " return(result) " ] }, { @@ -213,9 +366,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.117s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -232,19 +397,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ - "def unique(lst_un):\n", - "#your code here" + "\n", + "def unique(lst):\n", + " lst_un = []\n", + " for i in lst:\n", + " if i not in lst_un:\n", + " lst_un.append(i)\n", + " return lst_un \n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.225s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -260,19 +443,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", - "#your code here" + " freq = {}\n", + " for item in arr:\n", + " freq[item] = freq.get(item, 0) + 1\n", + "\n", + " mode = None\n", + " max_freq = 0\n", + " for item, count in freq.items():\n", + " if count > max_freq:\n", + " max_freq = count\n", + " mode = item\n", + " return mode" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.098s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" @@ -288,19 +493,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 92, "metadata": {}, "outputs": [], "source": [ "def st_dev(list_sd):\n", - "#your code here" + " #claculate the length of the list\n", + " count_len = 0\n", + " for i in list_sd:\n", + " count_len += 1\n", + " \n", + " #calculate the sum of the list\n", + " total = 0\n", + " for num in list_sd:\n", + " total += num\n", + "\n", + " #calculate the mean\n", + " mean = total/count_len\n", + "\n", + " #Calculate variance\n", + " variance_sum = 0\n", + " for x in list_sd:\n", + " variance_sum += (x - mean) ** 2\n", + " variance = variance_sum / (count_len-1)\n", + "\n", + " #Manual square root using Newton-Raphson\n", + " def sqrt(value):\n", + " guess = value/2\n", + " for _ in range(100):\n", + " guess = 0.5 * (guess + value / guess)\n", + " return guess\n", + "\n", + " return sqrt(variance)\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 93, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "............................................." + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + ".......................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.309s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -315,19 +566,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ "def pangram(string):\n", - "#your code here" + " # Step 1: Create alphabet manually\n", + " alphabet = ''\n", + " for i in range(26):\n", + " alphabet += chr(97 + i) # ASCII for 'a' to 'z'\n", + "\n", + " # Step 2: Track which letters appear\n", + " found = ''\n", + " for char in string:\n", + " lower = char.lower()\n", + " if 'a' <= lower <= 'z' and lower not in found:\n", + " found += lower\n", + "\n", + " # Step 3: Check if all letters are found\n", + " return len(found) == 26" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.025s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -344,19 +620,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, "outputs": [], "source": [ "def sort_alpha(string):\n", - "#your code here" + " # Step 1: Manually split the string into words\n", + " words = []\n", + " word = ''\n", + " for char in string:\n", + " if char == ',':\n", + " words.append(word)\n", + " word = ''\n", + " else:\n", + " word += char\n", + " words.append(word) # Add the last word\n", + "\n", + " # Step 2: Sort the list\n", + " sorted_words = sorted(words)\n", + "\n", + " # Step 3: Manually rebuild the comma-separated string\n", + " result = ''\n", + " for i in range(len(sorted_words)):\n", + " result += sorted_words[i]\n", + " if i < len(sorted_words) - 1:\n", + " result += ','\n", + "\n", + " return result" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.100s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -371,19 +680,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "def check_pass(password):\n", - "#your code here" + " if len(password) < 8:\n", + " return False\n", + "\n", + " has_lower = False\n", + " has_upper = False\n", + " has_digit = False\n", + " has_special = False\n", + "\n", + " for char in password:\n", + " if 'a' <= char <= 'z':\n", + " has_lower = True\n", + " elif 'A' <= char <= 'Z':\n", + " has_upper = True\n", + " elif '0' <= char <= '9':\n", + " has_digit = True\n", + " else:\n", + " has_special = True\n", + "\n", + " return has_lower and has_upper and has_digit and has_special" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 75, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.094s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" @@ -392,7 +731,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -406,12 +745,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.5" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-313.pyc b/mod/__pycache__/testing.cpython-313.pyc new file mode 100644 index 0000000..11d46a4 Binary files /dev/null and b/mod/__pycache__/testing.cpython-313.pyc differ