From a255ce004d49d82d382216f664896354e249e43f Mon Sep 17 00:00:00 2001 From: lzhanggit Date: Tue, 11 Feb 2020 09:56:36 -0600 Subject: [PATCH 1/5] 4 --- .ipynb_checkpoints/Week4-checkpoint.ipynb | 81 +++++++++++++++++++++++ Week4.ipynb | 81 +++++++++++++++++++++++ 2 files changed, 162 insertions(+) create mode 100644 .ipynb_checkpoints/Week4-checkpoint.ipynb create mode 100644 Week4.ipynb diff --git a/.ipynb_checkpoints/Week4-checkpoint.ipynb b/.ipynb_checkpoints/Week4-checkpoint.ipynb new file mode 100644 index 0000000..8ce4295 --- /dev/null +++ b/.ipynb_checkpoints/Week4-checkpoint.ipynb @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.Note : Use ’continue’ statement.Expected Output : 0 1 2 4 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Write a Python program to check the validity of password input by users.Validation :\n", + " At least 1 letter between [a-z] and 1 letter between [A-Z].\n", + " At least 1 number between [0-9].\n", + " At least 1 character from [$ # @].\n", + " Minimum length 6 characters.\n", + " Maximum length 16 characters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Maximum length 16 characters.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Week4.ipynb b/Week4.ipynb new file mode 100644 index 0000000..8ce4295 --- /dev/null +++ b/Week4.ipynb @@ -0,0 +1,81 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Write a Python program that prints all the numbers from 0 to 6 except 3 and 6.Note : Use ’continue’ statement.Expected Output : 0 1 2 4 5" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Write a Python program to check the validity of password input by users.Validation :\n", + " At least 1 letter between [a-z] and 1 letter between [A-Z].\n", + " At least 1 number between [0-9].\n", + " At least 1 character from [$ # @].\n", + " Minimum length 6 characters.\n", + " Maximum length 16 characters." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Maximum length 16 characters.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 315fd9e7818416b37a19a8d13bb2d4c73318e61c Mon Sep 17 00:00:00 2001 From: lzhanggit Date: Tue, 11 Feb 2020 18:06:14 -0600 Subject: [PATCH 2/5] 4 --- .ipynb_checkpoints/Untitled-checkpoint.ipynb | 6 + .ipynb_checkpoints/Untitled1-checkpoint.ipynb | 6 + .ipynb_checkpoints/Week4-checkpoint.ipynb | 125 ++++++++++++++++-- Untitled.ipynb | 6 + Untitled1.ipynb | 6 + Week4.ipynb | 125 ++++++++++++++++-- 6 files changed, 254 insertions(+), 20 deletions(-) create mode 100644 .ipynb_checkpoints/Untitled-checkpoint.ipynb create mode 100644 .ipynb_checkpoints/Untitled1-checkpoint.ipynb create mode 100644 Untitled.ipynb create mode 100644 Untitled1.ipynb diff --git a/.ipynb_checkpoints/Untitled-checkpoint.ipynb b/.ipynb_checkpoints/Untitled-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/.ipynb_checkpoints/Untitled-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/.ipynb_checkpoints/Untitled1-checkpoint.ipynb b/.ipynb_checkpoints/Untitled1-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/.ipynb_checkpoints/Untitled1-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/.ipynb_checkpoints/Week4-checkpoint.ipynb b/.ipynb_checkpoints/Week4-checkpoint.ipynb index 8ce4295..f5d1d98 100644 --- a/.ipynb_checkpoints/Week4-checkpoint.ipynb +++ b/.ipynb_checkpoints/Week4-checkpoint.ipynb @@ -9,16 +9,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1 2 4 5 \n" + ] + } + ], + "source": [ + "for x in range(6):\n", + " if (x == 3 or x == 6):\n", + " continue\n", + " print(x,end=' ')\n", + "print(\"\")" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Write a Python program to check the validity of password input by users.Validation :\n", + "2. Write a Python program to check the validity of password input by users.Validation :\n", " At least 1 letter between [a-z] and 1 letter between [A-Z].\n", " At least 1 number between [0-9].\n", " At least 1 character from [$ # @].\n", @@ -28,16 +42,84 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Input your password11\n", + "Not a Valid Password\n" + ] + } + ], + "source": [ + "import re\n", + "p= input(\"Input your password\")\n", + "x = True\n", + "while x: \n", + " if (len(p)<6 or len(p)>16):\n", + " break\n", + " elif not re.search(\"[a-z]\",p):\n", + " break\n", + " elif not re.search(\"[0-9]\",p):\n", + " break\n", + " elif not re.search(\"[A-Z]\",p):\n", + " break\n", + " elif not re.search(\"[$#@]\",p):\n", + " break\n", + " elif re.search(\"\\s\",p):\n", + " break\n", + " else:\n", + " print(\"Valid Password\")\n", + " x=False\n", + " break\n", + "\n", + "if x:\n", + " print(\"Not a Valid Password\")" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Maximum length 16 characters.\n" + "3. Write a Python program to construct the following pattern, using a nested for loop." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "* \n", + "* * \n", + "* * * \n", + "* * * * \n", + "* * * * * \n", + "* * * * \n", + "* * * \n", + "* * \n", + "* \n" + ] + } + ], + "source": [ + "n=5;\n", + "for i in range(n):\n", + " for j in range(i):\n", + " print ('* ', end=\"\")\n", + " print('')\n", + "\n", + "for i in range(n,0,-1):\n", + " for j in range(i):\n", + " print('* ', end=\"\")\n", + " print('')" ] }, { @@ -45,8 +127,29 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 4)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ - "\n" + "Brand = [Ford, Ford, Chevy, Chevy, Honda, Ford, Honda, Honda, Ford, Chevy]\n", + "Model = [F150, Escape, Charger, Charger, Civic, Escape, CRV, CRV, F150, Silverado]\n", + "Type = [Pickup, SUV, Sedan, Sedan, Sedan, SUV, SUV, SUV, Pickup, Pickup]\n", + "Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\n", + "#Find the brand and model of the safest car\n", + "print(\"a\", min(Accidents each year))" ] }, { @@ -54,7 +157,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "\n" + ] } ], "metadata": { diff --git a/Untitled.ipynb b/Untitled.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/Untitled.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Untitled1.ipynb b/Untitled1.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/Untitled1.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Week4.ipynb b/Week4.ipynb index 8ce4295..479eca3 100644 --- a/Week4.ipynb +++ b/Week4.ipynb @@ -9,16 +9,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1 2 4 5 \n" + ] + } + ], + "source": [ + "for x in range(6):\n", + " if (x == 3 or x == 6):\n", + " continue\n", + " print(x,end=' ')\n", + "print(\"\")" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Write a Python program to check the validity of password input by users.Validation :\n", + "2. Write a Python program to check the validity of password input by users.Validation :\n", " At least 1 letter between [a-z] and 1 letter between [A-Z].\n", " At least 1 number between [0-9].\n", " At least 1 character from [$ # @].\n", @@ -28,16 +42,84 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Input your password11\n", + "Not a Valid Password\n" + ] + } + ], + "source": [ + "import re\n", + "p= input(\"Input your password\")\n", + "x = True\n", + "while x: \n", + " if (len(p)<6 or len(p)>16):\n", + " break\n", + " elif not re.search(\"[a-z]\",p):\n", + " break\n", + " elif not re.search(\"[0-9]\",p):\n", + " break\n", + " elif not re.search(\"[A-Z]\",p):\n", + " break\n", + " elif not re.search(\"[$#@]\",p):\n", + " break\n", + " elif re.search(\"\\s\",p):\n", + " break\n", + " else:\n", + " print(\"Valid Password\")\n", + " x=False\n", + " break\n", + "\n", + "if x:\n", + " print(\"Not a Valid Password\")" + ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "Maximum length 16 characters.\n" + "3. Write a Python program to construct the following pattern, using a nested for loop." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "* \n", + "* * \n", + "* * * \n", + "* * * * \n", + "* * * * * \n", + "* * * * \n", + "* * * \n", + "* * \n", + "* \n" + ] + } + ], + "source": [ + "n=5;\n", + "for i in range(n):\n", + " for j in range(i):\n", + " print ('* ', end=\"\")\n", + " print('')\n", + "\n", + "for i in range(n,0,-1):\n", + " for j in range(i):\n", + " print('* ', end=\"\")\n", + " print('')" ] }, { @@ -45,8 +127,29 @@ "execution_count": null, "metadata": {}, "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 4)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ - "\n" + "Brand = [Ford, Ford, Chevy, Chevy, Honda, Ford, Honda, Honda, Ford, Chevy]\n", + "Model = [F150, Escape, Charger, Charger, Civic, Escape, CRV, CRV, F150, Silverado]\n", + "Type = [Pickup, SUV, Sedan, Sedan, Sedan, SUV, SUV, SUV, Pickup, Pickup]\n", + "Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\n", + "#Find the brand and model of the safest car\n", + "min(Accidents each year)" ] }, { @@ -54,7 +157,9 @@ "execution_count": null, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "\n" + ] } ], "metadata": { From 3041b51161ac1165d46b90ab78cc8e2603342070 Mon Sep 17 00:00:00 2001 From: lzhanggit Date: Wed, 12 Feb 2020 09:08:40 -0600 Subject: [PATCH 3/5] namechange --- ...Week4-checkpoint.ipynb => Week4_Ligang_Zhang-checkpoint.ipynb} | 0 Week4.ipynb => Week4_Ligang_Zhang.ipynb | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename .ipynb_checkpoints/{Week4-checkpoint.ipynb => Week4_Ligang_Zhang-checkpoint.ipynb} (100%) rename Week4.ipynb => Week4_Ligang_Zhang.ipynb (100%) diff --git a/.ipynb_checkpoints/Week4-checkpoint.ipynb b/.ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb similarity index 100% rename from .ipynb_checkpoints/Week4-checkpoint.ipynb rename to .ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb diff --git a/Week4.ipynb b/Week4_Ligang_Zhang.ipynb similarity index 100% rename from Week4.ipynb rename to Week4_Ligang_Zhang.ipynb From 4a53f129bdae39b7b477da07cd45f72e36774be0 Mon Sep 17 00:00:00 2001 From: lzhanggit Date: Wed, 12 Feb 2020 11:32:11 -0600 Subject: [PATCH 4/5] 7 --- .ipynb_checkpoints/Untitled2-checkpoint.ipynb | 6 + .../Week4_Ligang_Zhang-checkpoint.ipynb | 152 +++++++++++++++++- Untitled2.ipynb | 52 ++++++ Week4_Ligang_Zhang.ipynb | 144 ++++++++++++++++- 4 files changed, 344 insertions(+), 10 deletions(-) create mode 100644 .ipynb_checkpoints/Untitled2-checkpoint.ipynb create mode 100644 Untitled2.ipynb diff --git a/.ipynb_checkpoints/Untitled2-checkpoint.ipynb b/.ipynb_checkpoints/Untitled2-checkpoint.ipynb new file mode 100644 index 0000000..2fd6442 --- /dev/null +++ b/.ipynb_checkpoints/Untitled2-checkpoint.ipynb @@ -0,0 +1,6 @@ +{ + "cells": [], + "metadata": {}, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/.ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb b/.ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb index f5d1d98..82aaec4 100644 --- a/.ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb +++ b/.ipynb_checkpoints/Week4_Ligang_Zhang-checkpoint.ipynb @@ -131,15 +131,15 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "ename": "SyntaxError", - "evalue": "invalid syntax (, line 4)", + "evalue": "invalid syntax (, line 4)", "output_type": "error", "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" ] } ], @@ -149,17 +149,155 @@ "Type = [Pickup, SUV, Sedan, Sedan, Sedan, SUV, SUV, SUV, Pickup, Pickup]\n", "Accidents each year = [25, 79, 46, 90, 29, 88, 79, 93, 20, 11]\n", "#Find the brand and model of the safest car\n", - "print(\"a\", min(Accidents each year))" + "min(Accidents each year)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Classify daily temperatures (in degrees Celsius) stored in the temperatures list belowinto four different classes:\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-5.4, -4.8, -4.4, -2.2, -3.9, -2.5, -4.6, -2.4, -3.3, -4.8, -2.8, -4.7, -5.6, -2.7, -4.6]\n", + "[1.0, -1.3, 0.1, 1.9, 1.0, -0.8, -0.1, -0.4, -0.9, 1.6, 1.8, 1.6, 1.5, 1.4, 1.6, -0.0]\n", + "[3.9, 4.0, 4.4, 5.1, 2.1, 2.6, 3.4, 3.1, 2.4, 4.2, 3.5, 2.6, 3.1, 2.2, 3.3, 4.7, 4.0, 3.6, 4.9, 4.8, 5.3, 5.6, 4.1, 3.7, 7.6, 6.9, 5.1, 6.4, 3.8, 4.0, 8.6, 4.1, 8.9, 3.0, 8.5, 4.7, 6.6, 8.1, 4.5, 4.8, 11.3, 4.7, 5.2, 11.5, 6.2, 2.9, 4.3, 2.8, 2.8, 6.3, 2.6, 7.3, 3.4, 4.7, 9.3, 6.4, 5.4, 7.6, 5.2]\n", + "[]\n", + "-3.913333333333333\n", + "0.625\n", + "5.018644067796609\n" + ] + } + ], "source": [ - "\n" + "temperatures = [-5.4, 1.0, -1.3, -4.8, 3.9, 0.1, -4.4, 4.0, -2.2, -3.9, 4.4, -2.5, -4.6, \n", + " 5.1, 2.1, -2.4, 1.9, -3.3, -4.8, 1.0, -0.8, -2.8, -0.1, -4.7, -5.6, 2.6,\n", + "-2.7, -4.6, 3.4, -0.4, -0.9, 3.1, 2.4, 1.6, 4.2, 3.5, 2.6, 3.1, 2.2, 1.8, 3.3,\n", + "1.6, 1.5, 4.7, 4.0, 3.6, 4.9, 4.8, 5.3, 5.6, 4.1, 3.7, 7.6, 6.9, 5.1, 6.4, 3.8,\n", + "4.0, 8.6, 4.1, 1.4, 8.9, 3.0, 1.6, 8.5, 4.7, 6.6, 8.1, 4.5, 4.8, 11.3, 4.7, 5.2,\n", + "11.5, 6.2, 2.9, 4.3, 2.8, 2.8, 6.3, 2.6, -0.0, 7.3, 3.4, 4.7, 9.3, 6.4, 5.4, 7.6,\n", + "5.2]\n", + "cold = [n for n in temperatures if n <= -2]\n", + "slippery = [n for n in temperatures if n <= 2 and n > -2]\n", + "comfortable = [n for n in temperatures if n > 2 and n <= 15]\n", + "warm = [n for n in temperatures if n > 15]\n", + "print(cold)\n", + "print(slippery)\n", + "print(comfortable)\n", + "print(warm)\n", + "def ave(num):\n", + " nsum = 0\n", + " for i in range(len(num)):\n", + " nsum += num[i]\n", + " return nsum / len(num)\n", + "print(ave(cold))\n", + "print(ave(slippery))\n", + "print(ave(comfortable))\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Given a string, find the length of the longest substring without repeating characters." + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "ename": "IndentationError", + "evalue": "unindent does not match any outer indentation level (, line 17)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m17\u001b[0m\n\u001b[1;33m pos[string[i]] = i\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n" + ] + } + ], + "source": [ + "def findLongestSubstring(string): \n", + " n = len(string) \n", + " st = 0\n", + " maxlen = 0\n", + " start = 0\n", + " pos = {} \n", + " pos[string[0]] = 0\n", + " for i in range(1, n): \n", + " if string[i] not in pos: \n", + " pos[string[i]] = i \n", + " else: \n", + " currlen = i - st \n", + " if maxlen < currlen: \n", + " maxlen = currlen \n", + " start = st \n", + " st = pos[string[i]] + 1\n", + " pos[string[i]] = i \n", + " if maxlen < i - st: \n", + " maxlen = i - st \n", + " start = st \n", + " return string[start : start + maxlen] \n", + "findLongestSubstring(\"hhhhhasdhhha\"){}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "7. Given an array nums of n integers, are there elements a, b, c in nums such that a + b +\n", + "c = 0? Find all unique triplets in the array which gives the sum of zero. The solution set\n", + "must not contain duplicate triplets." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 -1 1\n", + "2 -3 1\n" + ] + } + ], + "source": [ + "def findTriplets(arr, n): \n", + " found = True\n", + " for i in range(0, n-2): \n", + " for j in range(i+1, n-1): \n", + " for k in range(j+1, n): \n", + " if (arr[i] + arr[j] + arr[k] == 0): \n", + " print(arr[i], arr[j], arr[k]) \n", + " found = True\n", + " if (found == False): \n", + " print(\" not exist \") \n", + "\n", + "arr = [0, -1, 2, -3, 1] \n", + "n = len(arr) \n", + "findTriplets(arr, n) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { diff --git a/Untitled2.ipynb b/Untitled2.ipynb new file mode 100644 index 0000000..cf8f1ed --- /dev/null +++ b/Untitled2.ipynb @@ -0,0 +1,52 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'hello$$$'" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "\"{:$<8s}\".format(\"hello\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Week4_Ligang_Zhang.ipynb b/Week4_Ligang_Zhang.ipynb index 479eca3..82aaec4 100644 --- a/Week4_Ligang_Zhang.ipynb +++ b/Week4_Ligang_Zhang.ipynb @@ -152,14 +152,152 @@ "min(Accidents each year)" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Classify daily temperatures (in degrees Celsius) stored in the temperatures list belowinto four different classes:\n" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-5.4, -4.8, -4.4, -2.2, -3.9, -2.5, -4.6, -2.4, -3.3, -4.8, -2.8, -4.7, -5.6, -2.7, -4.6]\n", + "[1.0, -1.3, 0.1, 1.9, 1.0, -0.8, -0.1, -0.4, -0.9, 1.6, 1.8, 1.6, 1.5, 1.4, 1.6, -0.0]\n", + "[3.9, 4.0, 4.4, 5.1, 2.1, 2.6, 3.4, 3.1, 2.4, 4.2, 3.5, 2.6, 3.1, 2.2, 3.3, 4.7, 4.0, 3.6, 4.9, 4.8, 5.3, 5.6, 4.1, 3.7, 7.6, 6.9, 5.1, 6.4, 3.8, 4.0, 8.6, 4.1, 8.9, 3.0, 8.5, 4.7, 6.6, 8.1, 4.5, 4.8, 11.3, 4.7, 5.2, 11.5, 6.2, 2.9, 4.3, 2.8, 2.8, 6.3, 2.6, 7.3, 3.4, 4.7, 9.3, 6.4, 5.4, 7.6, 5.2]\n", + "[]\n", + "-3.913333333333333\n", + "0.625\n", + "5.018644067796609\n" + ] + } + ], "source": [ - "\n" + "temperatures = [-5.4, 1.0, -1.3, -4.8, 3.9, 0.1, -4.4, 4.0, -2.2, -3.9, 4.4, -2.5, -4.6, \n", + " 5.1, 2.1, -2.4, 1.9, -3.3, -4.8, 1.0, -0.8, -2.8, -0.1, -4.7, -5.6, 2.6,\n", + "-2.7, -4.6, 3.4, -0.4, -0.9, 3.1, 2.4, 1.6, 4.2, 3.5, 2.6, 3.1, 2.2, 1.8, 3.3,\n", + "1.6, 1.5, 4.7, 4.0, 3.6, 4.9, 4.8, 5.3, 5.6, 4.1, 3.7, 7.6, 6.9, 5.1, 6.4, 3.8,\n", + "4.0, 8.6, 4.1, 1.4, 8.9, 3.0, 1.6, 8.5, 4.7, 6.6, 8.1, 4.5, 4.8, 11.3, 4.7, 5.2,\n", + "11.5, 6.2, 2.9, 4.3, 2.8, 2.8, 6.3, 2.6, -0.0, 7.3, 3.4, 4.7, 9.3, 6.4, 5.4, 7.6,\n", + "5.2]\n", + "cold = [n for n in temperatures if n <= -2]\n", + "slippery = [n for n in temperatures if n <= 2 and n > -2]\n", + "comfortable = [n for n in temperatures if n > 2 and n <= 15]\n", + "warm = [n for n in temperatures if n > 15]\n", + "print(cold)\n", + "print(slippery)\n", + "print(comfortable)\n", + "print(warm)\n", + "def ave(num):\n", + " nsum = 0\n", + " for i in range(len(num)):\n", + " nsum += num[i]\n", + " return nsum / len(num)\n", + "print(ave(cold))\n", + "print(ave(slippery))\n", + "print(ave(comfortable))\n" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Given a string, find the length of the longest substring without repeating characters." + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "ename": "IndentationError", + "evalue": "unindent does not match any outer indentation level (, line 17)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m17\u001b[0m\n\u001b[1;33m pos[string[i]] = i\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mIndentationError\u001b[0m\u001b[1;31m:\u001b[0m unindent does not match any outer indentation level\n" + ] + } + ], + "source": [ + "def findLongestSubstring(string): \n", + " n = len(string) \n", + " st = 0\n", + " maxlen = 0\n", + " start = 0\n", + " pos = {} \n", + " pos[string[0]] = 0\n", + " for i in range(1, n): \n", + " if string[i] not in pos: \n", + " pos[string[i]] = i \n", + " else: \n", + " currlen = i - st \n", + " if maxlen < currlen: \n", + " maxlen = currlen \n", + " start = st \n", + " st = pos[string[i]] + 1\n", + " pos[string[i]] = i \n", + " if maxlen < i - st: \n", + " maxlen = i - st \n", + " start = st \n", + " return string[start : start + maxlen] \n", + "findLongestSubstring(\"hhhhhasdhhha\"){}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "7. Given an array nums of n integers, are there elements a, b, c in nums such that a + b +\n", + "c = 0? Find all unique triplets in the array which gives the sum of zero. The solution set\n", + "must not contain duplicate triplets." + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 -1 1\n", + "2 -3 1\n" + ] + } + ], + "source": [ + "def findTriplets(arr, n): \n", + " found = True\n", + " for i in range(0, n-2): \n", + " for j in range(i+1, n-1): \n", + " for k in range(j+1, n): \n", + " if (arr[i] + arr[j] + arr[k] == 0): \n", + " print(arr[i], arr[j], arr[k]) \n", + " found = True\n", + " if (found == False): \n", + " print(\" not exist \") \n", + "\n", + "arr = [0, -1, 2, -3, 1] \n", + "n = len(arr) \n", + "findTriplets(arr, n) " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { From c8402f65f442528a99da98c2d7fd66e435baa766 Mon Sep 17 00:00:00 2001 From: lzhanggit Date: Wed, 29 Apr 2020 19:22:59 -0500 Subject: [PATCH 5/5] 1 --- .ipynb_checkpoints/7.3-checkpoint.ipynb | 56 +++++++++++++++++++++++++ 7.3.ipynb | 56 +++++++++++++++++++++++++ 2 files changed, 112 insertions(+) create mode 100644 .ipynb_checkpoints/7.3-checkpoint.ipynb create mode 100644 7.3.ipynb diff --git a/.ipynb_checkpoints/7.3-checkpoint.ipynb b/.ipynb_checkpoints/7.3-checkpoint.ipynb new file mode 100644 index 0000000..2f11260 --- /dev/null +++ b/.ipynb_checkpoints/7.3-checkpoint.ipynb @@ -0,0 +1,56 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PythonNRES 7.3 " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Based on the information at http://www.rcc-acis.org/docs_webservices.html, write Python functions that\n", + "1. return a dataframe that includes the daily climate data for a list of stations between a given period\n", + "2. return a dataframe that includes the pentad mean climate data for a list of stations between a given period\n", + "3. return a dataframe that includes the monthly mean climate data for a given county and a given period" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import urllib2\n", + "import json\n", + "\n", + "import pandas as pd\n", + "from pandas import DataFrame, Panel\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/7.3.ipynb b/7.3.ipynb new file mode 100644 index 0000000..2f11260 --- /dev/null +++ b/7.3.ipynb @@ -0,0 +1,56 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# PythonNRES 7.3 " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## 3. Based on the information at http://www.rcc-acis.org/docs_webservices.html, write Python functions that\n", + "1. return a dataframe that includes the daily climate data for a list of stations between a given period\n", + "2. return a dataframe that includes the pentad mean climate data for a list of stations between a given period\n", + "3. return a dataframe that includes the monthly mean climate data for a given county and a given period" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import urllib2\n", + "import json\n", + "\n", + "import pandas as pd\n", + "from pandas import DataFrame, Panel\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}