diff --git a/main.ipynb b/main.ipynb index b05630a..b56c04d 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,44 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def greater(a,b):\n", - "#your code here" + " return max(a, b)\n", + "\n", + "greater(2,3)" ] }, { "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.052s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" @@ -57,7 +82,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -73,18 +98,48 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "#your code here" + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], + "source": [ + "lista = [2, 5, 10, 4, 3, 7, 8]\n", + "\n", + "def greatest(l):\n", + " max_num = l[0]\n", + " for num in l:\n", + " if num > max_num:\n", + " max_num = num\n", + " return max_num\n", + "\n", + "print(greatest(lista)) # Output: 10\n", + "\n" ] }, { "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.057s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" @@ -99,21 +154,50 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "39" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def sum_all(lst):\n", - "#your code here" + "\n", + " total = 0\n", + " for num in lst:\n", + " total += num\n", + " return total\n", + "\n", + "sum_all(lista)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.057s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" @@ -128,21 +212,49 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "67200" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def mult_all(lst):\n", - "#your code here" + " total = 1\n", + " for num in lst:\n", + " total *= num\n", + " return total\n", + " \n", + "mult_all(lista)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.076s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mult(mult_all)" @@ -157,19 +269,52 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "17\n", + "100\n" + ] + } + ], "source": [ "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + " result = arr[0]\n", + " for num in arr[1:]:\n", + " if oper == \"+\":\n", + " result += num\n", + " elif oper == \"*\":\n", + " result *= num\n", + " else:\n", + " raise ValueError(\"Operator must be '+' or '*'\")\n", + " return result\n", + "\n", + "print(oper_all([2, 5, 10], \"+\"))\n", + "print(oper_all([2, 5, 10], \"*\")) \n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.060s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -184,17 +329,39 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def factorial(n):\n", - "#your code here" + " if n == 0:\n", + " return 1\n", + " \n", + " if n < 0:\n", + " raise ValueError(\"Factorial is not defined for negative numbers.\")\n", + " else:\n", + " result = 1\n", + " for i in range(2, n + 1):\n", + " result *= i\n", + " return result\n", + "\n", + "factorial(2)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -213,9 +380,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.057s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -232,19 +411,52 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 3, 5, 6, 7, 8, 9]" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list1 = [2, 2, 3, 3 ,5, 6, 7, 7 ,8, 8, 9]\n", + "\n", "def unique(lst_un):\n", - "#your code here" + " new_list = []\n", + " for i in lst_un:\n", + " if i not in new_list:\n", + " new_list.append(i)\n", + " return new_list\n", + "\n", + "unique(list1)\n", + "\n", + "\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.106s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -262,17 +474,67 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], "source": [ - "def mode_counter(arr):\n", - "#your code here" + "\n", + "def mode_counter(data):\n", + " #freq = {2:1,3:2, 5:1, 7:2, 8:1 }\n", + " freq = {}\n", + " \n", + " # Count frequencies manually\n", + " for num in data: \n", + " if num in freq:\n", + " freq[num] += 1\n", + " else:\n", + " freq[num] = 1\n", + "\n", + " # Find the highest frequency\n", + " highest = 0 \n", + " mode = 0\n", + " for key in freq:\n", + " if freq[key] > highest:\n", + " highest = freq[key]\n", + " mode = key\n", + "\n", + " return mode\n", + "\n", + "data = [2, 3, 3, 5, 7, 7, 8]\n", + "print(mode_counter(data))\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "........................." + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "...........................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.178s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" @@ -288,19 +550,73 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2.3804761428476167" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def st_dev(list_sd):\n", - "#your code here" + " # length of list\n", + " length = 0\n", + " for _ in list_sd:\n", + " length += 1\n", + "\n", + " # Calculate mean\n", + " total = 0\n", + " for i in list_sd:\n", + " total += i\n", + " mean = total / len(list_sd)\n", + "\n", + " # calculate square difference\n", + " square_diff = []\n", + " for num in list_sd:\n", + " square_diff.append((num - mean) ** 2)\n", + "\n", + " # calculate variance\n", + " variance = 0\n", + " for num in square_diff:\n", + " variance += num\n", + " variance /= (length - 1 )\n", + "\n", + " # return square root of variance\n", + " sd = variance ** 0.5\n", + "\n", + " return sd\n", + "\n", + "\n", + "\n", + "data = [2, 3, 3, 5, 7, 7, 8]\n", + "st_dev(data)\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 71, + "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_stdev(st_dev)" @@ -317,17 +633,55 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], "source": [ "def pangram(string):\n", - "#your code here" + "\n", + " alphabet = \"abcdefghijklmnopqrstuvwxyz\"\n", + " \n", + " string = string.lower()\n", + " \n", + " for letter in alphabet:\n", + " if letter not in string:\n", + " return False \n", + " \n", + " return True \n", + "\n", + " \n", + "sentence = \"The quick brown fox jumps over the lazy dog\"\n", + "print(pangram(sentence))\n", + "\n", + "sentence2 = \"Hello world\"\n", + "print(pangram(sentence2))\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 79, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.020s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -344,19 +698,71 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple,banana,cherry,mango\n" + ] + } + ], "source": [ "def sort_alpha(string):\n", - "#your code here" + " word = \"\"\n", + " words = []\n", + "\n", + " # Extract words manually\n", + " for char in string:\n", + " if char != \",\":\n", + " word += char\n", + " else:\n", + " words.append(word.strip())\n", + " word = \"\"\n", + " if word:\n", + " words.append(word.strip())\n", + "\n", + " # Sort manually\n", + " for i in range(len(words)):\n", + " for j in range(i + 1, len(words)):\n", + " if words[i] > words[j]:\n", + " temp = words[i]\n", + " words[i] = words[j]\n", + " words[j] = temp\n", + "\n", + " # Join into a single string\n", + " result = \"\"\n", + " for i in range(len(words)):\n", + " result += words[i]\n", + " if i != len(words) - 1:\n", + " result += \",\"\n", + "\n", + " return result\n", + "\n", + "\n", + "input_text = \" mango ,apple, banana , cherry\"\n", + "print(sort_alpha(input_text)) # Output: \"apple,banana,cherry,mango\"\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.071s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -371,28 +777,87 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n" + ] + } + ], "source": [ "def check_pass(password):\n", - "#your code here" + " # Rule 1: Minimum length\n", + " if len(password) < 8:\n", + " return False\n", + "\n", + " # Flags for each requirement\n", + " has_lower = False\n", + " has_upper = False\n", + " has_digit = False\n", + " has_special = False\n", + "\n", + " # Check each character\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 # Anything not a letter or digit\n", + "\n", + " # Final check\n", + " if has_lower and has_upper and has_digit and has_special:\n", + " return True\n", + " else:\n", + " return False\n", + " \n", + "print(check_pass(\"Python@123\")) # True\n", + "print(check_pass(\"weakpass\")) # False\n", + "print(check_pass(\"NoSpecial1\")) # False\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 83, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.060s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -406,12 +871,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..2477fd9 Binary files /dev/null and b/mod/__pycache__/testing.cpython-313.pyc differ