From 24fd580ae6e98248c4ea39347929fad622bb3f06 Mon Sep 17 00:00:00 2001 From: lenovo Date: Thu, 7 Jul 2022 17:54:11 +0200 Subject: [PATCH] J --- main.ipynb | 415 +++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 352 insertions(+), 63 deletions(-) diff --git a/main.ipynb b/main.ipynb index 73f285a..176d300 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,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ "def greater(a,b):\n", - " pass" + " if a>b:\n", + " return a\n", + " if b>a:\n", + " return b\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.054s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greater(greater)" @@ -64,19 +79,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, "outputs": [], "source": [ "def greatest(arr):\n", - " pass" + " valor = 1\n", + " for i in arr:\n", + " if i > valor:\n", + " valor = i\n", + " return valor\n", + " " ] }, { "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.055s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_greatest(greatest)" @@ -91,19 +123,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": {}, "outputs": [], "source": [ "def sum_all(arr):\n", - " pass" + " total = 0\n", + " for i in arr:\n", + " total += i\n", + " return total" ] }, { "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.054s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_sum(sum_all)" @@ -118,19 +165,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, "outputs": [], "source": [ "def mult_all(arr):\n", - " pass" + " result = 1\n", + " for x in arr:\n", + " result = result * x\n", + " return result" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.050s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_mult(mult_all)" @@ -145,19 +207,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, "outputs": [], "source": [ "def oper_all(arr, oper):\n", - " pass" + " if oper == \"+\":\n", + " total = 0\n", + " for i in arr:\n", + " total += i\n", + " return total\n", + " else:\n", + " result = 1\n", + " for x in arr:\n", + " result = result * x\n", + " return result\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.051s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_operations(oper_all)" @@ -172,19 +256,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "def factorial(n):\n", - " pass" + " total = 1\n", + " for i in range(1,n+1):\n", + " total *= i\n", + " return total\n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.051s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_factorial(factorial)" @@ -201,19 +301,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ "def unique(arr):\n", - " pass" + " list = []\n", + " for i in arr:\n", + " if i in list:\n", + " pass\n", + " else:\n", + " list.append(i)\n", + " return list\n", + " " ] }, { "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 0.098s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_unique(unique)" @@ -229,19 +348,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ "def mode_counter(arr):\n", - " pass" + "\n", + " counts = {}\n", + " \n", + " for item in arr:\n", + " if item in counts:\n", + " counts[item] += 1\n", + " else:\n", + " counts[item] = 1\n", + " i = 0\n", + " top = 0 \n", + " for key, value in counts.items():\n", + " if value > i:\n", + " i = value\n", + " top = key\n", + " \n", + " return top" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 69, + "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_mode(mode_counter)" @@ -257,20 +403,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 102, "metadata": {}, "outputs": [], "source": [ "from statistics import stdev\n", "def st_dev(arr):\n", - " pass" + " total = 0\n", + " list = []\n", + " deviation = []\n", + " length = len(arr)\n", + " for i in arr:\n", + " total += i\n", + " list.append(i)\n", + "\n", + " total = total/length\n", + " for i in arr:\n", + " deviation.append(abs(i-total)**2)\n", + " sum = 0\n", + " for i in deviation:\n", + " sum += i\n", + " length -= 1\n", + " total = sum/length\n", + " total = total**(1/2)\n", + " return total\n", + " \n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 103, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.053s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_stdev(st_dev)" @@ -285,19 +462,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 115, "metadata": {}, "outputs": [], "source": [ "def pangram(string):\n", - " pass" + " alphabet = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + " sentence = string\n", + " list = []\n", + " missing = \"\"\n", + " for letter in string:\n", + " if letter in alphabet:\n", + " if letter not in list:\n", + " list.append(letter)\n", + " \n", + " if len(list)>=26:\n", + " return True\n", + " else:\n", + " return False\n", + " " ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 116, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "..............................\n", + "----------------------------------------------------------------------\n", + "Ran 30 tests in 0.015s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pangram(pangram)" @@ -314,19 +516,43 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 121, "metadata": {}, "outputs": [], "source": [ "def sort_alpha(string):\n", - " pass" + " list = []\n", + " string += \",\"\n", + " word = \"\"\n", + " for i in string:\n", + " if i == \",\":\n", + " list.append(word)\n", + " word = \"\"\n", + " else:\n", + " word += i\n", + " list.sort()\n", + " word = \"\"\n", + " word = \",\".join(list)\n", + " return word\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.051s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_alpha(sort_alpha)" @@ -342,28 +568,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 205, "metadata": {}, "outputs": [], "source": [ "def check_pass(string):\n", - " pass" + " alphabet = \"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + " numbers = \"1234567890\"\n", + " special = \"#@!$%&()^*[]{}\"\n", + " upper_letter = False\n", + " lower_letter = False\n", + " count_letters = 0\n", + " special_boolean = False\n", + " numbers_boolean = False\n", + " count = 0\n", + " for letter in string:\n", + " count_letters +=1\n", + " if letter in alphabet:\n", + " if letter.isupper():\n", + " upper_letter = True\n", + " if letter.islower():\n", + " lower_letter = True\n", + " elif letter in numbers:\n", + " numbers_boolean = True\n", + " elif letter in special:\n", + " special_boolean = True\n", + " if count_letters >= 8 and upper_letter and lower_letter and special_boolean and numbers_boolean:\n", + " return True\n", + " else:\n", + " return False\n" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 206, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "....................................................................................................\n", + "----------------------------------------------------------------------\n", + "Ran 100 tests in 0.049s\n", + "\n", + "OK\n" + ] + } + ], "source": [ "# This will test your function \n", "test_pass(check_pass)" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -377,7 +666,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.6" + "version": "3.9.12" } }, "nbformat": 4,