From 1cce9dda4d316908d3cd662b4d2e33506fe375d5 Mon Sep 17 00:00:00 2001 From: Wilmer Date: Wed, 8 Oct 2025 17:10:03 +0100 Subject: [PATCH 1/2] initial commit day 3 --- .DS_Store | Bin 0 -> 6148 bytes main.ipynb | 363 +++++++++++++++++++----- mod/__pycache__/testing.cpython-313.pyc | Bin 0 -> 20232 bytes 3 files changed, 299 insertions(+), 64 deletions(-) create mode 100644 .DS_Store create mode 100644 mod/__pycache__/testing.cpython-313.pyc diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..ac764e5d51e4dd879e14b1f2138f332196cd4098 GIT binary patch literal 6148 zcmeHKO>Yx15FIBe-K9dx0R)#ymbgYCsR|O}vV`=&flC*`0Z`awBUrJuqkIsdDAHcx z&-B=T!rv)xY!|gnxzY;FNaHsi&)Dl{%U%xMLfXA7uY zA6+VGLf^?yz7Z{so5%pK-EBIe3@c~o-1@z&?5Di4ypFs%o{}5n(_W5C*Q7fpFMGJJfK@Bf3pzyB{LNlh3K2L3AsRBM b:\n", + " return a\n", + " else:\n", + " return b\n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.481s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "#your code here" + "## 2. Now write a function that returns the largest element on a list" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 27, "metadata": {}, + "outputs": [], "source": [ - "## 2. Now write a function that returns the largest element on a list" + "def largest_num(lst):\n", + " largest = lst[0]\n", + " for num in lst:\n", + " if num > largest:\n", + " largest = num \n", + "\n", + " return largest\n", + "\n", + "\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "def largest_in_list(numbers):\n", + " # assume the first element is the largest to start\n", + " largest = numbers[0]\n", + "\n", + " # loop through the list and update largest if we find a bigger number\n", + " for num in numbers:\n", + " if num > largest:\n", + " largest = num\n", + "\n", + " return largest" ] }, { "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.440s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", - "test_greatest(greatest)" + "test_greatest(largest_in_list)" ] }, { @@ -99,21 +145,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "def sum_all(lst):\n", - "#your code here" + "def sum_all(numbers):\n", + " total = 0\n", + " for num in numbers:\n", + " total += num\n", + "\n", + " return total\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.667s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" @@ -128,21 +190,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ "def mult_all(lst):\n", - "#your code here" + " product = 1 # start from 1 because multiplying by 0 would always give 0\n", + " \n", + " for num in lst:\n", + " product *= num\n", + " return product" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": { "scrolled": true }, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.547s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mult(mult_all)" @@ -157,19 +235,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper = \"*\"):\n", - "#your code here" + "\n", + " if oper == \"+\":\n", + " total = 0\n", + " for num in arr:\n", + " total += num\n", + " return total\n", + " elif oper == \"*\":\n", + " product = 1\n", + " for num in arr:\n", + " product *= num\n", + " return product\n", + " else:\n", + " return \"Invalid operator\"\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 1.623s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -184,12 +286,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", - "#your code here" + " \n", + " if n < 0:\n", + " return \"Factorial not defined for negative numbers\"\n", + " \n", + " result = 1\n", + " for i in range(1, n + 1):\n", + " result *= i\n", + " return result" ] }, { @@ -213,9 +322,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 46, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 1.386s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -232,19 +353,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "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" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 3.403s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -260,19 +397,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", - "#your code here" + " freq = {}\n", + "\n", + " for item in arr:\n", + " if item in freq:\n", + " freq[item] += 1\n", + " else:\n", + " freq[item] = 1\n", + "\n", + " max_count = 0\n", + " mode_value = None\n", + "\n", + " for key in freq:\n", + " if freq[key] > max_count:\n", + " max_count = freq[key]\n", + " mode_value = key\n", + "\n", + " return mode_value\n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 51, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 3.111s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" @@ -288,19 +454,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, "outputs": [], "source": [ "def st_dev(list_sd):\n", - "#your code here" + " \n", + " # 1 Calculate the length manually\n", + " n = 0\n", + " for _ in list_sd:\n", + " n += 1\n", + "\n", + " # 2 Calculate the mean manually\n", + " total = 0\n", + " for x in list_sd:\n", + " total += x\n", + " mean = total / n\n", + "\n", + " # 3 Calculate the sum of squared differences\n", + " squared_diff_sum = 0\n", + " for x in list_sd:\n", + " squared_diff_sum += (x - mean) ** 2\n", + "\n", + " # 4 Apply Bessel's correction (divide by n - 1)\n", + " variance = squared_diff_sum / (n - 1)\n", + "\n", + " # 5 Standard deviation is the square root of variance\n", + " std_dev = variance ** 0.5\n", + " return std_dev" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 1.667s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -315,19 +515,59 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, "outputs": [], "source": [ "def pangram(string):\n", - "#your code here" + "\n", + " # 1 Convert letters to lowercase, to check case sensitive\n", + " string = string.lower()\n", + "\n", + " # 2 Keep track of letters we've seen\n", + " letters_seen = []\n", + "\n", + " # 3 Go through each character and store it if it's a letter a-z\n", + " for ch in string:\n", + " if \"a\" <= ch <= \"z\" and ch not in letters_seen:\n", + " letters_seen.append(ch)\n", + "\n", + " # 4 Count letters \n", + " count = 0\n", + " for _ in letters_seen:\n", + " count += 1\n", + "\n", + " # 5 Check if we saw all 26 letters\n", + " if count == 26:\n", + " return True\n", + " else:\n", + " return False " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "............................" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.320s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -392,7 +632,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -406,12 +646,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" - }, - "vscode": { - "interpreter": { - "hash": "aee8b7b246df8f9039afb4144a1f6fd8d2ca17a180786b69acc140d282b71a49" - } + "version": "3.13.7" } }, "nbformat": 4, diff --git a/mod/__pycache__/testing.cpython-313.pyc b/mod/__pycache__/testing.cpython-313.pyc new file mode 100644 index 0000000000000000000000000000000000000000..b01c0c43a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sE%qW}pJewUO@!HfczCRq`yW8p zI*#@QxHRj7U=utn(?0HZ;TjIs)afUDW}^<+2BkcW#aBE9htX(7`xi5SPu3_JDjg3%V2r^;8U2 zNjd8I*bO`1U>NX0fHG-s$IV3nqEL=&9M zflk1<1lI9j$#%ExfTqyamO&` zS3lWlz)ZTG^&LE?J|i<7R7gA9GAW z2RD2WG`nWbA-CC6*q+VY32df(C$pdgS(6Nzt{I--^C-B_r}V$UkS#__P^tel^u>Yw#Ula zr;0kDYcM4o;5O9T4&XUHTGrc~cj|4&Mq4km$BSyF%-iPD(jZT&o;f+$lwqo=%Qs$s ze{6hEJp6XP$yVzeM*@z-Q55y@5LGCUWUlfZ&@?Zi&$4 zFN6Sc69sk@(fhj=gUu+OM&U<6-7n7K*^4NCfZ}x&bXJ8{C90&;ewBBNti`z1AQI-s z Date: Thu, 9 Oct 2025 18:35:57 +0100 Subject: [PATCH 2/2] Final update lab done --- .DS_Store | Bin 6148 -> 6148 bytes main.ipynb | 183 +++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 137 insertions(+), 46 deletions(-) diff --git a/.DS_Store b/.DS_Store index ac764e5d51e4dd879e14b1f2138f332196cd4098..4eccaf639f8c7119e411b3cfed239afa560f7961 100644 GIT binary patch delta 93 zcmZoMXffDO&BVBEat%|Vt5|ilsgZ$>f words[j + 1]:\n", + " tmp = words[j]\n", + " words[j] = words[j + 1]\n", + " words[j + 1] = tmp\n", + " j += 1\n", + " i += 1\n", + "\n", + " # 4) Rebuild the CSV string (no join)\n", + " result = \"\"\n", + " idx = 0\n", + " last = n - 1\n", + " while idx < n:\n", + " result += words[idx]\n", + " if idx < last:\n", + " result += \",\"\n", + " idx += 1\n", + "\n", + " return result\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.588s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -611,19 +663,58 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n", + "False\n" + ] + } + ], "source": [ "def check_pass(password):\n", - "#your code here" + " if len(password) < 8:\n", + " return False\n", + "\n", + " has_lower = any(c.islower() for c in password)\n", + " has_upper = any(c.isupper() for c in password)\n", + " has_digit = any(c.isdigit() for c in password)\n", + " has_special = any(not c.isalnum() for c in password) # not letter or number\n", + "\n", + " return all([has_lower, has_upper, has_digit, has_special])\n", + "\n", + "\n", + "# Examples\n", + "print(check_pass(\"StrongPass1!\")) # ✅ True\n", + "print(check_pass(\"weakpass\")) # ❌ False\n", + "print(check_pass(\"HELLO123\")) # ❌ False\n", + "print(check_pass(\"Hi!2\")) # ❌ False\n", + "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.400s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" @@ -632,7 +723,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "base", "language": "python", "name": "python3" }, @@ -646,7 +737,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.7" + "version": "3.13.5" } }, "nbformat": 4,