diff --git a/main.ipynb b/main.ipynb index b05630a..d1fbb29 100644 --- a/main.ipynb +++ b/main.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -37,19 +37,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", + " if a > b:\n", + " return a #(f\"{a} is greater than {b}\")\n", + " elif a < b:\n", + " return b #(f\"{b} is greater than {a}\")\n", + " else:\n", + " return a # (\"They are both equal\")\n", + "\n", "#your code here" ] }, { "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.110s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" @@ -57,11 +76,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "#your code here" + "greater (5,5)" ] }, { @@ -73,18 +103,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ - "#your code here" + "#your code here\n", + "def greatest(lst):\n", + " if not lst:\n", + " raise error(\"list can not be empty\")\n", + " x = lst[0]\n", + " for i in lst:\n", + " if i > x:\n", + " x = i\n", + " return x\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.095s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" @@ -99,21 +150,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def sum_all(lst):\n", - "#your code here" + " x = 0\n", + " for i in lst:\n", + " x += i\n", + "\n", + " return x\n", + "\n", + " " ] }, { "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.109s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" @@ -128,21 +197,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ "def mult_all(lst):\n", - "#your code here" + " for i in range(0, len(lst)):\n", + " if i > 0:\n", + " previous_number = previous_number * lst[i]\n", + " else:\n", + " previous_number = lst[i]\n", + "\n", + " return previous_number\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": { "scrolled": true }, - "outputs": [], + "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_mult(mult_all)" @@ -157,19 +244,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper = \"*\"):\n", + " if oper == \"+\":\n", + " for i in range(0, len(arr)):\n", + " if i > 0:\n", + " previous_number = previous_number + arr[i]\n", + " else:\n", + " previous_number = arr[i]\n", + " elif oper == \"*\":\n", + " for i in range(0, len(arr)):\n", + " if i > 0:\n", + " previous_number = previous_number * arr[i]\n", + " else:\n", + " previous_number = arr[i]\n", + "\n", + " return previous_number\n", + "\n", "#your code here" ] }, { "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.098s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -184,11 +298,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", + " x = 1\n", + " for i in range(1, n + 1):\n", + " x *= i\n", + " return x\n", "#your code here" ] }, @@ -213,9 +331,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.101s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -232,19 +362,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ "def unique(lst_un):\n", + " values = []\n", + " unique_values = []\n", + " for i in lst_un:\n", + " if i not in values:\n", + " values.append(i)\n", + " unique_values.append(i) \n", + " return unique_values\n", + " \n", + "\n", + " \n", "#your code here" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.242s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -260,19 +412,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", + " numbers = {}\n", + " values = 0\n", + " keys = 0\n", + " for i in arr:\n", + " if i in numbers:\n", + " numbers[i] += 1\n", + " else:\n", + " numbers[i] = 1\n", + " for key,value in numbers.items():\n", + " if value > values:\n", + " values = value\n", + " keys = key\n", + " return keys\n", + "\n", "#your code here" ] }, { "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.104s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mode(mode_counter)" @@ -288,19 +466,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ "def st_dev(list_sd):\n", + " sum_numbers = 0\n", + " sqrd = 0\n", + " for i in list_sd:\n", + " sum_numbers += i\n", + " med = sum_numbers / len(list_sd)\n", + " for i in list_sd:\n", + " sqrd += (i - med) ** 2\n", + " var = sqrd / (len(list_sd) -1)\n", + " dev = var ** 0.5\n", + " return dev\n", + "\n", "#your code here" ] }, { "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 0.059s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -315,19 +516,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ "def pangram(string):\n", + " string = string.lower()\n", + " alphabet = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']\n", + " for i in alphabet:\n", + " if i not in string:\n", + " return False\n", + " return True\n", + "\n", + "\n", "#your code here" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.014s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -344,19 +565,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, "outputs": [], "source": [ "def sort_alpha(string):\n", + " words = []\n", + " sliced_word = \"\"\n", + " for i in string:\n", + " if i == ',':\n", + " words.append(sliced_word)\n", + " sliced_word = \"\"\n", + " else:\n", + " sliced_word += i\n", + " words.append(sliced_word)\n", + "\n", + " words.sort()\n", + "\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", "#your code here" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.058s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -371,19 +625,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "def check_pass(password):\n", + " if len(password) < 8:\n", + " return False\n", + " \n", + " lower = False\n", + " upper = False\n", + " digit = False\n", + " special = False\n", + "\n", + " for i in password:\n", + " if i.islower():\n", + " lower = True\n", + " elif i.isupper():\n", + " upper = True\n", + " elif i.isdigit():\n", + " digit = True\n", + " elif not i.isalnum():\n", + " special = True\n", + "\n", + " if lower == True and upper == True and digit == True and special == True:\n", + " return True\n", + " else:\n", + " return False\n", "#your code here" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.062s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" @@ -392,7 +680,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -406,12 +694,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..6ff3627 Binary files /dev/null and b/mod/__pycache__/testing.cpython-312.pyc differ