diff --git a/module-1/lab-advanced-regex/your-code/main.ipynb b/module-1/lab-advanced-regex/your-code/main.ipynb index b898da503..f15e56648 100644 --- a/module-1/lab-advanced-regex/your-code/main.ipynb +++ b/module-1/lab-advanced-regex/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -27,7 +27,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -36,10 +36,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['i', 'i', 'o', 'i', 'o', 'e', 'a', 'e', 'e', 'e', 'i', 'a', 'o', 'o', 'u', 'e', 'o', 'o', 'e', 'i', 'i']\n" + ] + } + ], + "source": [ + "all_vowels = re.findall('[aeiou]',text)\n", + "print(all_vowels)" + ] }, { "cell_type": "markdown", @@ -50,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -59,10 +70,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['puppy', 'puppies', 'puppy']\n" + ] + } + ], + "source": [ + "Puppy = re.findall('puppy|puppies',text)\n", + "print(Puppy)" + ] }, { "cell_type": "markdown", @@ -73,7 +95,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -82,10 +104,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ran', 'run']\n" + ] + } + ], + "source": [ + "Run = re.findall('r[au]n', text)\n", + "print(Run)" + ] }, { "cell_type": "markdown", @@ -96,10 +129,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ran', 'relay', 'race', 'run']\n" + ] + } + ], + "source": [ + "letter_r = re.findall('[r]\\w+',text)\n", + "print(letter_r)" + ] }, { "cell_type": "markdown", @@ -110,7 +154,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -119,10 +163,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This is a sentence with special characters in it.\n" + ] + } + ], + "source": [ + "exclamation = re.sub('!','i',text)\n", + "print(exclamation)" + ] }, { "cell_type": "markdown", @@ -133,7 +188,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -142,10 +197,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sentence', 'words', 'varying', 'lengths']\n" + ] + } + ], + "source": [ + "longerthan4 = re.findall('\\w{5,}',text)\n", + "print(longerthan4)" + ] }, { "cell_type": "markdown", @@ -156,7 +222,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, "outputs": [], "source": [ @@ -165,10 +231,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I', 'b', 'e', 't', 't', 'h', 'e', 'r', 'o', 'b', 'o', 't', 'c', 'o', 'u', 'l', 'd', 'n', 't', 'b', 'e', 'a', 't', 't', 'h', 'e', 'o', 't', 'h', 'e', 'r', 'b', 'o', 't', 'w', 'i', 't', 'h', 'a', 'b', 'a', 't', 'b', 'u', 't', 'i', 'n', 's', 't', 'e', 'a', 'd', 'i', 't', 'b', 'i', 't', 'm', 'e']\n" + ] + } + ], + "source": [ + "bsomet = re.findall('[b]|[\\w]|[t]',text)\n", + "print(bsomet)" + ] }, { "cell_type": "markdown", @@ -179,7 +256,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 107, "metadata": {}, "outputs": [], "source": [ @@ -188,10 +265,22 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['peaks', 'people', 'realize', 'breathtaking', 'Nearly']\n" + ] + } + ], + "source": [ + "eaoreo = re.findall('\\w+ea\\w+|\\w+eo\\w+',text)\n", + "\n", + "print(eaoreo)" + ] }, { "cell_type": "markdown", @@ -202,7 +291,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ @@ -211,10 +300,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Teddy', 'Roosevelt', 'Abraham', 'Lincoln']\n" + ] + } + ], + "source": [ + "capitalized = re.findall('[A-Z]\\w+',text)\n", + "print(capitalized)" + ] }, { "cell_type": "markdown", @@ -225,10 +325,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Teddy Roosevelt', 'Abraham Lincoln']\n" + ] + } + ], + "source": [ + "consecutive_capitalized = re.findall('[A-Z]\\w+ ?[A-Z]\\w+',text)\n", + "print(consecutive_capitalized)" + ] }, { "cell_type": "markdown", @@ -241,7 +352,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, "outputs": [], "source": [ @@ -250,10 +361,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['\"I will bet you $50 I can get the bartender to give me a free drink.\" Lincoln says, \"I am in!\"']\n" + ] + } + ], + "source": [ + "quotes = re.findall('\".*\"',text)\n", + "print(quotes)" + ] }, { "cell_type": "markdown", @@ -264,7 +386,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 67, "metadata": {}, "outputs": [], "source": [ @@ -273,10 +395,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['30', '30', '14', '16', '10']\n" + ] + } + ], + "source": [ + "allnumbers = re.findall('\\d+',text)\n", + "print(allnumbers)" + ] }, { "cell_type": "markdown", @@ -287,7 +420,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "metadata": {}, "outputs": [], "source": [ @@ -299,10 +432,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 73, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['876-93-2289', '098-32-5295']\n" + ] + } + ], + "source": [ + "SSN = re.findall('\\d{3}-\\d{2}-\\d{4}',text)\n", + "print(SSN)" + ] }, { "cell_type": "markdown", @@ -313,10 +457,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['(847)789-0984', '(987)222-0901']\n" + ] + } + ], + "source": [ + "phone_number = re.findall('\\(\\d{3}\\)\\d{3}-\\d{4}',text)\n", + "print(phone_number)" + ] }, { "cell_type": "markdown", @@ -325,6 +480,42 @@ "### 15. Use a regular expression to find and extract all the formatted numbers (both social security and phone) from the text below." ] }, + { + "cell_type": "code", + "execution_count": 87, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['876-93-2289', '(847)789-0984', '98-32-5295', '(987)222-0901']\n" + ] + } + ], + "source": [ + "formatted_number = re.findall('[\\+\\(]?[1-9][0-9 .\\-\\(\\)]{8,}[0-9]',text)\n", + "print(formatted_number)" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['876-93-2289', '(847)789-0984', '098-32-5295', '(987)222-0901']\n" + ] + } + ], + "source": [ + "formatted_number = re.findall('\\(?\\d+\\)?\\d+-?\\d+-?\\d+',text)\n", + "print(formatted_number)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -349,7 +540,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-error-handling/your-code/main.ipynb b/module-1/lab-error-handling/your-code/main.ipynb index 860e6f7d8..e2c049aa1 100644 --- a/module-1/lab-error-handling/your-code/main.ipynb +++ b/module-1/lab-error-handling/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 42, "metadata": {}, "outputs": [], "source": [ @@ -32,51 +32,93 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], "source": [ "# Modify the code below:\n", - "\n", - "print(some_string)" + "try: \n", + " print(some_string)\n", + "except:\n", + " print(\"NameError: some_string is not defined.\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'.\n" + ] + } + ], "source": [ "# Modify the code below:\n", "\n", - "for i in ['a','b','c']:\n", - " print (i**2)" + "try:\n", + " for i in ['a','b','c']:\n", + " print (i**2)\n", + "except:\n", + " print(\"TypeError: unsupported operand type(s) for ** or pow(): 'str' and 'int'.\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "ZeroDivisionError: y = 0/ division by zero\n" + ] + } + ], "source": [ "# Modify the code below:\n", + "try:\n", + " x = 5\n", + " y = 0\n", "\n", - "x = 5\n", - "y = 0\n", - "\n", - "z = x/y" + " z = x/y\n", + "except:\n", + " print(\"ZeroDivisionError: y = 0/ division by zero\")" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "IndexError: list index out of range; list abc does not have index 3.\n" + ] + } + ], "source": [ "# Modify the code below:\n", "\n", - "abc=[10,20,20]\n", - "print(abc[3])" + "try:\n", + " abc=[10,20,20]\n", + " print(abc[3])\n", + "except:\n", + " print(\"IndexError: list index out of range; list abc does not have index 3.\")" ] }, { @@ -92,20 +134,25 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 31, "metadata": {}, "outputs": [ { - "ename": "ValueError", - "evalue": "math domain error", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mValueError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0msqrt_for_all\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36msqrt_for_all\u001b[1;34m(x)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;31m# Sample Input: -4\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;31m# Sample Output: 2.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mmath\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msqrt\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0msqrt_for_all\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m-\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mValueError\u001b[0m: math domain error" + "name": "stdout", + "output_type": "stream", + "text": [ + "The number entered raises a math domain error! Function executed with absolute value.\n" ] + }, + { + "data": { + "text/plain": [ + "1.0" + ] + }, + "execution_count": 31, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -115,30 +162,39 @@ " # This function will take any real number and return the square root of its magnitude\n", " # Input: real number\n", " # Output: real number\n", - " \n", + " if x > 0:\n", + " return math.sqrt(x)\n", + " else:\n", + " print(\"The number entered raises a math domain error! Function executed with absolute value.\")\n", + " x = abs(x)\n", + " return math.sqrt(x)\n", " # Sample Input: -4\n", " # Sample Output: 2.0\n", - " return math.sqrt(x)\n", - "\n", - "sqrt_for_all(-1)" + " \n", + "sqrt_for_all(-1)\n" ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 34, "metadata": {}, "outputs": [ { - "ename": "ZeroDivisionError", - "evalue": "division by zero", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mZeroDivisionError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\u001b[1;33m \u001b[0mdivide\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36mdivide\u001b[1;34m(x, y)\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[1;31m# Sample Input: 5, 1\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;31m# Sample Output: 5.0\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 10\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0mx\u001b[0m \u001b[1;33m/\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 11\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[0mdivide\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m0\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mZeroDivisionError\u001b[0m: division by zero" + "name": "stdout", + "output_type": "stream", + "text": [ + "The number entered raises a Zero Division Error! Function still executes.\n" ] + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" } ], "source": [ @@ -148,33 +204,33 @@ " # This function will take any two real numbers and return their quotient. If the denominator is zero, we return zero\n", " # Input: real number\n", " # Output: real number\n", - " \n", + " if y != 0:\n", + " return x / y\n", + " else:\n", + " print(\"The number entered raises a Zero Division Error! Function still executes.\")\n", + " return 0\n", " # Sample Input: 5, 1\n", " # Sample Output: 5.0\n", - " return x / y\n", + " \n", "\n", "divide(5, 0)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 20, "metadata": {}, "outputs": [ { - "ename": "TypeError", - "evalue": "'int' object is not iterable", - "output_type": "error", - "traceback": [ - "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", - "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m()\u001b[0m\n\u001b[0;32m 14\u001b[0m \u001b[1;32mreturn\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0ma\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0melement\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0melement\u001b[0m \u001b[1;32min\u001b[0m \u001b[0ml\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 16\u001b[1;33m \u001b[0madd_elements\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m6\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", - "\u001b[1;32m\u001b[0m in \u001b[0;36madd_elements\u001b[1;34m(a, l)\u001b[0m\n\u001b[0;32m 12\u001b[0m \u001b[1;31m# Sample Input: 5, 6\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 13\u001b[0m \u001b[1;31m# Sample Output: [11]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 14\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0ma\u001b[0m \u001b[1;33m+\u001b[0m \u001b[0melement\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0melement\u001b[0m \u001b[1;32min\u001b[0m \u001b[0ml\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 15\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 16\u001b[0m \u001b[0madd_elements\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;36m5\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m6\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", - "\u001b[1;31mTypeError\u001b[0m: 'int' object is not iterable" + "name": "stdout", + "output_type": "stream", + "text": [ + "TypeError: 'int' object is not iterable. Cannot return value of 'a + element for element in l'.\n" ] } ], "source": [ + "import numbers\n", "# Modify the function below that it will take either an number and a list or two numbers. \n", "# If we take two numbers, add them together and return a list of length 1. \n", "# Otherwise, add the number to every element of the list and return the resulting list\n", @@ -182,13 +238,19 @@ "def add_elements(a, l):\n", " # This function takes either two numbers or a list and a number and adds the number to all elements of the list\n", " # If the function only takes two numbers, it returns a list of length one that is the sum of the numbers\n", - " \n", + " if type(l) != type(numbers.Number):\n", + " print(\"TypeError: 'int' object is not iterable. Cannot return value of 'a + element for element in l'.\")\n", + " else:\n", + " if type(l) == type(numbers.Number):\n", + " return sum(a + l)\n", + " \n", + " \n", " # Input: number and list or two numbers\n", " # Output: list\n", " \n", " # Sample Input: 5, 6\n", " # Sample Output: [11]\n", - " return [a + element for element in l]\n", + " #return [a + element for element in l]\n", " \n", "add_elements(5, 6)" ] @@ -204,29 +266,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Modify the code below:\n", "\n", "l = [1,2,3,4]\n", "\n", - "sum([element + 1 for element in l]" + "sum( l)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The current element in the loop is 1\n", + "The current element in the loop is 2\n", + "The current element in the loop is 3\n", + "The current element in the loop is 4\n" + ] + } + ], "source": [ "# Modify the code below:\n", "\n", "l = [1,2,3,4]\n", "\n", "for element in l:\n", - " print(\"The current element in the loop is\" + element)" + " print(\"The current element in the loop is\", element)" ] }, { @@ -240,39 +324,71 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "3.2188758248682006" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def log_square(x):\n", " # This function takes a numeric value and returns the natural log of the square of the number \n", " # The function raises an error if the number is equal to zero\n", " # Use the math.log function in this funtion\n", - " \n", + " number = x\n", + " if math.log(x**2) == 0:\n", + " raise ValueError(\"The outcome number equal to zero.\")\n", + " else:\n", + " return math.log(x**2)\n", " # Input: real number\n", " # Output: real number or error\n", " \n", " # Sample Input: 5\n", " # Sample Output: 3.21887\n", " \n", - " # Your code here:" + " # Your code here:\n", + "log_square(5)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def check_capital(x):\n", " # This function returns true if the string contains at least one capital letter and throws an error otherwise\n", " # Input: string\n", " # Output: bool or error message\n", - " \n", + " for i in x:\n", + " if i.isupper():\n", + " return bool(i)\n", + " else:\n", + " raise ValueError(\"String does not contain any capital letter.\")\n", " # Sample Input: 'John'\n", " # Sample Output: True\n", " \n", - " # Your code here:" + " # Your code here:\n", + "check_capital(\"John\")" ] }, { @@ -323,7 +439,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-functional-programming/your-code/main.ipynb b/module-1/lab-functional-programming/your-code/main.ipynb index 8017d6e62..cf8f56c3d 100644 --- a/module-1/lab-functional-programming/your-code/main.ipynb +++ b/module-1/lab-functional-programming/your-code/main.ipynb @@ -12,7 +12,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -146,10 +146,19 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n" + ] + } + ], "source": [ + "\n", "def divisible2(iterator):\n", " # This function takes an iterable and returns the first element that is divisible by 2 and zero otherwise\n", " # Input: Iterable\n", @@ -158,8 +167,15 @@ " # Sample Input: iter([1,2,3])\n", " # Sample Output: 2\n", " \n", - " # Your code here:\n", - " " + " # Your code here: \n", + "\n", + " iterator = iter([1,2,3]) \n", + " for i in iterator:\n", + " if i % 2 == 0:\n", + " print(i)\n", + "# else:\n", + "# (print(\"0\"))\n", + "divisible2(iterator)" ] }, { @@ -173,7 +189,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -193,7 +209,7 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -224,7 +240,7 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": null, "metadata": {}, "outputs": [], "source": [ @@ -237,7 +253,19 @@ " # Sample Output: iter([0, 2, 4])\n", " \n", " # Your code here:\n", - " " + " number = 0\n", + " while number < n:\n", + " if number % 2 == 0:\n", + " yield number\n", + " number = number + 1\n", + " \n", + "iteratoreven = []\n", + "iterator = even_iterator(5)\n", + "for i in iterator:\n", + " iteratoreven.append(i)\n", + " \n", + "even_iterator(5)\n", + "print(iteratoreven)" ] }, { @@ -253,7 +281,7 @@ }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -270,12 +298,101 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_widthiris_type
05.13.51.40.2Iris-setosa
14.93.01.40.2Iris-setosa
24.73.21.30.2Iris-setosa
34.63.11.50.2Iris-setosa
45.03.61.40.2Iris-setosa
\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width iris_type\n", + "0 5.1 3.5 1.4 0.2 Iris-setosa\n", + "1 4.9 3.0 1.4 0.2 Iris-setosa\n", + "2 4.7 3.2 1.3 0.2 Iris-setosa\n", + "3 4.6 3.1 1.5 0.2 Iris-setosa\n", + "4 5.0 3.6 1.4 0.2 Iris-setosa" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "iris_df = iris.head()\n", + "iris_df\n", + "#Jupyter cannot connect to kernel that I can't see anything..." ] }, { @@ -287,12 +404,32 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 11, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 4.86\n", + "sepal_width 3.28\n", + "petal_length 1.40\n", + "petal_width 0.20\n", + "dtype: float64" + ] + }, + "execution_count": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_mean = np.mean(iris_df)\n", + "iris_mean\n", + "#Jupyter cannot connect to kernel that I can't see anything...\n", + "#No idea if my code works\n", + "#Guessing it calculates the mean of the data provided from dataframe iris..." ] }, { @@ -304,12 +441,32 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 0.185472\n", + "sepal_width 0.231517\n", + "petal_length 0.063246\n", + "petal_width 0.000000\n", + "dtype: float64" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_std = np.std(iris_df)\n", + "iris_std\n", + "#Jupyter cannot connect to kernel that I can't see anything...\n", + "#No idea if my code works\n", + "#Guessing it calculates the standard deviation of the data provided from dataframe iris..." ] }, { @@ -321,12 +478,146 @@ }, { "cell_type": "code", - "execution_count": 19, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
sepal_lengthsepal_widthpetal_lengthpetal_width
05.13.51.40.2
14.93.01.40.2
24.73.21.30.2
34.63.11.50.2
45.03.61.40.2
...............
1456.73.05.22.3
1466.32.55.01.9
1476.53.05.22.0
1486.23.45.42.3
1495.93.05.11.8
\n", + "

150 rows × 4 columns

\n", + "
" + ], + "text/plain": [ + " sepal_length sepal_width petal_length petal_width\n", + "0 5.1 3.5 1.4 0.2\n", + "1 4.9 3.0 1.4 0.2\n", + "2 4.7 3.2 1.3 0.2\n", + "3 4.6 3.1 1.5 0.2\n", + "4 5.0 3.6 1.4 0.2\n", + ".. ... ... ... ...\n", + "145 6.7 3.0 5.2 2.3\n", + "146 6.3 2.5 5.0 1.9\n", + "147 6.5 3.0 5.2 2.0\n", + "148 6.2 3.4 5.4 2.3\n", + "149 5.9 3.0 5.1 1.8\n", + "\n", + "[150 rows x 4 columns]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_numeric = iris._get_numeric_data()\n", + "iris_numeric" ] }, { @@ -338,7 +629,7 @@ }, { "cell_type": "code", - "execution_count": 21, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -351,7 +642,8 @@ " # Sample Output: 0.393701\n", " \n", " # Your code here:\n", - " " + " original_value = x\n", + " numerica_value_in = print(float(x % 0.393701)) " ] }, { @@ -363,12 +655,26 @@ }, { "cell_type": "code", - "execution_count": 22, + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "iris_inch = []\n", + "for columns in iris_inch:\n", + " for val in columns:\n", + " valnew = cm_to_in(val)\n", + " iris_inch.append(valnew)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, "metadata": {}, "outputs": [], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_inch = set(iris_inch)" ] }, { @@ -380,12 +686,13 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ "# Define constant below:\n", "\n", + "constant_error = 2\n", "\n", "def add_constant(x):\n", " # This function adds a global constant to our input.\n", @@ -393,7 +700,10 @@ " # Output: numeric value\n", " \n", " # Your code here:\n", - " " + " original_value = x\n", + " updated_value = x + constant_error\n", + " \n", + "iris_constant = add_constant(iris_numeric)\n" ] }, { @@ -407,12 +717,28 @@ }, { "cell_type": "code", - "execution_count": 24, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "sepal_length 7.9\n", + "sepal_width 4.4\n", + "petal_length 6.9\n", + "petal_width 2.5\n", + "dtype: float64" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "\n", + "iris_numeric.max()" ] }, { @@ -428,8 +754,7 @@ "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n", - "\n" + "# Your code here:\n" ] }, { @@ -456,7 +781,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.6" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-lambda-functions/your-code/main.ipynb b/module-1/lab-lambda-functions/your-code/main.ipynb index 66a998499..1979423fc 100644 --- a/module-1/lab-lambda-functions/your-code/main.ipynb +++ b/module-1/lab-lambda-functions/your-code/main.ipynb @@ -34,18 +34,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 4, 5, 6, 7, 8, 9, 10, 11]\n" + ] + } + ], "source": [ - "l = [######]\n", - "f = lambda x: #define the lambda expression\n", + "import random\n", + "l = [i for i in range(10)] \n", + "f = lambda x: x + 2\n", "b = []\n", - "def modify_list(lst, fudduLambda):\n", - " for x in ####:\n", - " b.append(#####(x))\n", - "#Call modify_list(##,##)\n", - "#print b" + "def modify_list(l, f):\n", + " for x in l:\n", + " b.append(f(x))\n", + " #Call modify_list(##,##)\n", + "modify_list(l,f)\n", + "print(b)" ] }, { @@ -59,12 +69,24 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "273.15" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your code here:\n", - "\n" + "Cel_to_Kel = lambda x:x + 273.15\n", + "# Cel_to_Kel(0)" ] }, { @@ -76,13 +98,25 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[285.15, 296.15, 311.15, 218.14999999999998, 297.15]\n" + ] + } + ], "source": [ "temps = [12, 23, 38, -55, 24]\n", - "\n", - "# Your code here:" + "Kel = []\n", + "for x in temps:\n", + " Kel.append(Cel_to_Kel(x))\n", + "print(Kel)\n", + "# Your code here:\n", + "#comprehension: converted = [Cel_to_Kel(x) for x in temps]" ] }, { @@ -96,11 +130,12 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "mod = lambda x, y: 1 if x % y == 0 or y % x == 0 else 0\n" ] }, { @@ -114,17 +149,31 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 47, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "def divisor(b):\n", - " \"\"\"\n", - " input: a number\n", - " output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise\n", - " \"\"\"\n", + " return mod(5,b)\n", + "# divisor(1)\n", + "# input: a number\n", + "# output: a function that returns 1 if the number is divisible by another number (to be passed later) and zero otherwise\n", + "# \"\"\"\n", + " \n", + " # Your code here:\n", " \n", - " # Your code here:" + "#return lamdba later_arg: mod(b, later_arg)" ] }, { @@ -136,11 +185,25 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here:\n" + "# Your code here:\n", + "def divisible5(i):\n", + " return mod(5,i)\n", + "divisible5(5)" ] }, { @@ -152,18 +215,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 55, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(10)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 58, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 58, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "divisible5(8)" ] @@ -218,14 +303,27 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 61, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[(1, 2), (2, 3), (3, 4), (4, 5)]" + ] + }, + "execution_count": 61, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = [1,2,3,4]\n", "list2 = [2,3,4,5]\n", "## Zip the lists together \n", - "## Print the zipped list " + "zippedA = zip(list1, list2)\n", + "## Print the zipped list \n", + "list(zippedA)" ] }, { @@ -237,28 +335,32 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 77, "metadata": {}, "outputs": [ { - "data": { - "text/plain": [ - "'\\n\\ncompare = lambda ###: print(\"True\") if ### else print(\"False\")\\nfor ### in zip(list1,list2):\\n compare(###)\\n \\n'" - ] - }, - "execution_count": 4, - "metadata": {}, - "output_type": "execute_result" + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n", + "False\n", + "False\n" + ] } ], "source": [ - "'''\n", + "# '''\n", "\n", - "compare = lambda ###: print(\"True\") if ### else print(\"False\")\n", - "for ### in zip(list1,list2):\n", - " compare(###)\n", + "# compare = lambda ###: print(\"True\") if ### else print(\"False\")\n", + "# for ### in zip(list1,list2):\n", + "# compare(###)\n", " \n", - "''' " + "# ''' \n", + "\n", + "compare = lambda x,y: print(\"True\") if x > y else print(\"False\")\n", + "for x,y in zip(list1,list2):\n", + " compare(x,y)" ] }, { @@ -274,14 +376,33 @@ }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 50, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Political Science', 'Essay'),\n", + " ('Computer Science', 'Homework'),\n", + " ('Engineering', 'Lab'),\n", + " ('Mathematics', 'Module')]" + ] + }, + "execution_count": 50, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "list1 = ['Engineering', 'Computer Science', 'Political Science', 'Mathematics']\n", "list2 = ['Lab', 'Homework', 'Essay', 'Module']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "zippedB = list(zip(list1, list2)) \n", + "# zippedB\n", + "zipSorted = sorted(zippedB, key = lambda x: x[1])\n", + "zipSorted\n", + " " ] }, { @@ -295,21 +416,29 @@ }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[('Toyota', 1995), ('Honda', 1997), ('Audi', 2001), ('BMW', 2005)]" + ] + }, + "execution_count": 45, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "d = {'Honda': 1997, 'Toyota': 1995, 'Audi': 2001, 'BMW': 2005}\n", "\n", - "# Your code here:" + "# Your code here:\n", + "dList = [(k, v) for (k, v) in d.items()]\n", + "# dList\n", + "dSorted = sorted(dList, key = lambda x: x[1])\n", + "dSorted" ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] } ], "metadata": { diff --git a/module-1/lab-list-comprehensions/your-code/main.ipynb b/module-1/lab-list-comprehensions/your-code/main.ipynb index c5931c41f..abf1d5c5a 100644 --- a/module-1/lab-list-comprehensions/your-code/main.ipynb +++ b/module-1/lab-list-comprehensions/your-code/main.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -29,10 +29,72 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n", + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n", + "20\n", + "21\n", + "22\n", + "23\n", + "24\n", + "25\n", + "26\n", + "27\n", + "28\n", + "29\n", + "30\n", + "31\n", + "32\n", + "33\n", + "34\n", + "35\n", + "36\n", + "37\n", + "38\n", + "39\n", + "40\n", + "41\n", + "42\n", + "43\n", + "44\n", + "45\n", + "46\n", + "47\n", + "48\n", + "49\n", + "50\n" + ] + } + ], + "source": [ + "lst = range(51)\n", + "for i in lst:\n", + " if i != 0:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -43,10 +105,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200]\n" + ] + } + ], + "source": [ + "lst = range(201)\n", + "newlst = [val for val in lst if val > 1]\n", + "print(newlst)\n", + " " + ] }, { "cell_type": "markdown", @@ -57,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, "outputs": [], "source": [ @@ -75,10 +150,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.48006452, 0.7876326, 0.77109654, 0.44409793, 0.09014516, 0.81835917, 0.87645456, 0.7066597, 0.09610873, 0.41247947, 0.57433389, 0.29960807, 0.42315023, 0.34452557, 0.4751035, 0.17003563, 0.46843998, 0.92796258, 0.69814654, 0.41290051, 0.19561071, 0.16284783, 0.97016248, 0.71725408, 0.87702738, 0.31244595, 0.76615487, 0.20754036, 0.57871812, 0.07214068, 0.40356048, 0.12149553, 0.53222417, 0.9976855, 0.12536346, 0.80930099, 0.50962849, 0.94555126, 0.33364763]\n" + ] + } + ], + "source": [ + "import os\n", + "import numpy as np\n", + "import pandas as pd\n", + "a = np.array([[0.84062117, 0.48006452, 0.7876326 , 0.77109654],\n", + " [0.44409793, 0.09014516, 0.81835917, 0.87645456],\n", + " [0.7066597 , 0.09610873, 0.41247947, 0.57433389],\n", + " [0.29960807, 0.42315023, 0.34452557, 0.4751035 ],\n", + " [0.17003563, 0.46843998, 0.92796258, 0.69814654],\n", + " [0.41290051, 0.19561071, 0.16284783, 0.97016248],\n", + " [0.71725408, 0.87702738, 0.31244595, 0.76615487],\n", + " [0.20754036, 0.57871812, 0.07214068, 0.40356048],\n", + " [0.12149553, 0.53222417, 0.9976855 , 0.12536346],\n", + " [0.80930099, 0.50962849, 0.94555126, 0.33364763]])\n", + "newa = [val for sublist in a for val in sublist]\n", + "print(newa)" + ] }, { "cell_type": "markdown", @@ -89,10 +188,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.84062117, 0.7876326, 0.77109654, 0.81835917, 0.87645456, 0.7066597, 0.57433389, 0.92796258, 0.69814654, 0.97016248, 0.71725408, 0.87702738, 0.76615487, 0.57871812, 0.53222417, 0.9976855, 0.80930099, 0.50962849, 0.94555126]\n" + ] + } + ], + "source": [ + "import os\n", + "import numpy as np\n", + "import pandas as pd\n", + "a = np.array([[0.84062117, 0.48006452, 0.7876326 , 0.77109654],\n", + " [0.44409793, 0.09014516, 0.81835917, 0.87645456],\n", + " [0.7066597 , 0.09610873, 0.41247947, 0.57433389],\n", + " [0.29960807, 0.42315023, 0.34452557, 0.4751035 ],\n", + " [0.17003563, 0.46843998, 0.92796258, 0.69814654],\n", + " [0.41290051, 0.19561071, 0.16284783, 0.97016248],\n", + " [0.71725408, 0.87702738, 0.31244595, 0.76615487],\n", + " [0.20754036, 0.57871812, 0.07214068, 0.40356048],\n", + " [0.12149553, 0.53222417, 0.9976855 , 0.12536346],\n", + " [0.80930099, 0.50962849, 0.94555126, 0.33364763]])\n", + "newa = [val for sublist in a for val in sublist if val >= 0.5]\n", + "print(newa)" + ] }, { "cell_type": "markdown", @@ -125,10 +248,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.55867166, 0.82579068, 0.91512478, 0.65857693, 0.96031863, 0.51293743, 0.71893382, 0.58256464, 0.59005654, 0.56266457, 0.71600294, 0.87392666, 0.8694668, 0.65669313, 0.65368638]\n" + ] + } + ], + "source": [ + "import os\n", + "import numpy as np\n", + "import pandas as pd\n", + "b = np.array([[[0.55867166, 0.06210792, 0.08147297],\n", + " [0.82579068, 0.91512478, 0.06833034]],\n", + "\n", + " [[0.05440634, 0.65857693, 0.30296619],\n", + " [0.06769833, 0.96031863, 0.51293743]],\n", + "\n", + " [[0.09143215, 0.71893382, 0.45850679],\n", + " [0.58256464, 0.59005654, 0.56266457]],\n", + "\n", + " [[0.71600294, 0.87392666, 0.11434044],\n", + " [0.8694668 , 0.65669313, 0.10708681]],\n", + "\n", + " [[0.07529684, 0.46470767, 0.47984544],\n", + " [0.65368638, 0.14901286, 0.23760688]]])\n", + "subb2 = [b[0][0], b[0][1], b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1], b[4][0], b[4][1]]\n", + "newlistb2 = [val for sublist in subb2 for val in sublist if val >= 0.5]\n", + "print(newlistb2)" + ] }, { "cell_type": "markdown", @@ -139,10 +291,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0.06210792, 0.08147297, 0.06833034, 0.05440634, 0.30296619, 0.06769833, 0.09143215, 0.45850679, 0.11434044, 0.10708681, 0.07529684, 0.46470767, 0.47984544, 0.14901286, 0.23760688]\n" + ] + } + ], + "source": [ + "import os\n", + "import numpy as np\n", + "import pandas as pd\n", + "b = np.array([[[0.55867166, 0.06210792, 0.08147297],\n", + " [0.82579068, 0.91512478, 0.06833034]],\n", + "\n", + " [[0.05440634, 0.65857693, 0.30296619],\n", + " [0.06769833, 0.96031863, 0.51293743]],\n", + "\n", + " [[0.09143215, 0.71893382, 0.45850679],\n", + " [0.58256464, 0.59005654, 0.56266457]],\n", + "\n", + " [[0.71600294, 0.87392666, 0.11434044],\n", + " [0.8694668 , 0.65669313, 0.10708681]],\n", + "\n", + " [[0.07529684, 0.46470767, 0.47984544],\n", + " [0.65368638, 0.14901286, 0.23760688]]])\n", + "\n", + "subb1 = [b[0][0], b[0][1], b[1][0], b[1][1], b[2][0], b[2][1], b[3][0], b[3][1], b[4][0], b[4][1]]\n", + "newlistb = [val for sublist in subb1 for val in sublist if val <= 0.5]\n", + "print(newlistb)\n", + "\n" + ] }, { "cell_type": "markdown", @@ -153,10 +336,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['sample_file_0.csv', 'sample_file_1.csv', 'sample_file_2.csv', 'sample_file_3.csv', 'sample_file_4.csv', 'sample_file_5.csv', 'sample_file_6.csv', 'sample_file_7.csv', 'sample_file_8.csv', 'sample_file_9.csv']\n" + ] + } + ], + "source": [ + "import os\n", + "Filenames = [ \n", + " filename for filename in os.listdir('C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data') \n", + " if filename.endswith(\".csv\")\n", + " ]\n", + "print(Filenames)\n" + ] }, { "cell_type": "markdown", @@ -167,10 +365,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "ename": "OSError", + "evalue": "Initializing from file failed", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mOSError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconcat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mfile\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendswith\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'.csv'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m(.0)\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;32mimport\u001b[0m \u001b[0mpandas\u001b[0m \u001b[1;32mas\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mdf\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mconcat\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mpd\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mread_csv\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mfile\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mos\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mlistdir\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data'\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mendswith\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;34m'.csv'\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mdf\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pandas\\io\\parsers.py\u001b[0m in \u001b[0;36mparser_f\u001b[1;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, squeeze, prefix, mangle_dupe_cols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, dialect, error_bad_lines, warn_bad_lines, delim_whitespace, low_memory, memory_map, float_precision)\u001b[0m\n\u001b[0;32m 683\u001b[0m )\n\u001b[0;32m 684\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 685\u001b[1;33m \u001b[1;32mreturn\u001b[0m \u001b[0m_read\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfilepath_or_buffer\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 686\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 687\u001b[0m \u001b[0mparser_f\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m__name__\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mname\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pandas\\io\\parsers.py\u001b[0m in \u001b[0;36m_read\u001b[1;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[0;32m 455\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 456\u001b[0m \u001b[1;31m# Create the parser.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 457\u001b[1;33m \u001b[0mparser\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mTextFileReader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfp_or_buf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 458\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 459\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mchunksize\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0miterator\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pandas\\io\\parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[0;32m 893\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"has_index_names\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mkwds\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"has_index_names\"\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 894\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 895\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_make_engine\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mengine\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 896\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 897\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0mclose\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pandas\\io\\parsers.py\u001b[0m in \u001b[0;36m_make_engine\u001b[1;34m(self, engine)\u001b[0m\n\u001b[0;32m 1133\u001b[0m \u001b[1;32mdef\u001b[0m \u001b[0m_make_engine\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mengine\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"c\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1134\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mengine\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"c\"\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1135\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mCParserWrapper\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1136\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1137\u001b[0m \u001b[1;32mif\u001b[0m \u001b[0mengine\u001b[0m \u001b[1;33m==\u001b[0m \u001b[1;34m\"python\"\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32m~\\Anaconda3\\lib\\site-packages\\pandas\\io\\parsers.py\u001b[0m in \u001b[0;36m__init__\u001b[1;34m(self, src, **kwds)\u001b[0m\n\u001b[0;32m 1904\u001b[0m \u001b[0mkwds\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m\"usecols\"\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0musecols\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1905\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1906\u001b[1;33m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_reader\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mparsers\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mTextReader\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0msrc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwds\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 1907\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munnamed_cols\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_reader\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0munnamed_cols\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 1908\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;32mpandas\\_libs\\parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader.__cinit__\u001b[1;34m()\u001b[0m\n", + "\u001b[1;32mpandas\\_libs\\parsers.pyx\u001b[0m in \u001b[0;36mpandas._libs.parsers.TextReader._setup_parser_source\u001b[1;34m()\u001b[0m\n", + "\u001b[1;31mOSError\u001b[0m: Initializing from file failed" + ] + } + ], + "source": [ + "import pandas as pd\n", + "\n", + "df = pd.concat([pd.read_csv('C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data') for file in os.listdir('C:\\\\Users\\\\sfy\\\\Documents\\\\IronHack\\\\data-labs\\\\module-1\\\\lab-list-comprehensions\\\\data') if file.endswith('.csv')])\n", + "df " + ] }, { "cell_type": "markdown", @@ -231,7 +454,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.0" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-mysql-select/your-code/solutions.sql b/module-1/lab-mysql-select/your-code/solutions.sql new file mode 100644 index 000000000..cfb787d68 --- /dev/null +++ b/module-1/lab-mysql-select/your-code/solutions.sql @@ -0,0 +1,73 @@ +SHOW DATABASES; +USE lab_mysql_select; + +--### Challenge 1 - Who Have Published What At Where? +CREATE TABLE challenge_1 + SELECT authors.au_id AS 'AUTHOR ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', title AS 'TITLE', pub_name AS 'PUBLISHER' + FROM authors JOIN titleauthor + ON authors.au_id = titleauthor.au_id + JOIN titles + ON titleauthor.title_id = titles.title_id + JOIN publishers + ON titles.pub_id = publishers.pub_id + ; +SELECT * FROM challenge_1; + +SELECT COUNT(authors.au_id) FROM authors; +SELECT COUNT(challenge_1.au_id) FROM challenge_1; + +--### Challenge 2 - Who Have Published How Many At Where? + +CREATE TABLE challenge_2 + SELECT au_id AS 'AUTHOR ID', au_lname AS 'LAST NAME', au_fname AS 'FIRST NAME', pub_name AS 'PUBLISHER', COUNT(title) AS 'TITLE COUNT' + FROM challenge_1 + GROUP BY au_lname, au_fname, pub_name + ORDER BY au_id DESC, COUNT(title) DESC + ; + +SELECT * FROM challenge_2; + +SELECT COUNT(titleauthor.title_id) FROM titleauthor; +SELECT COUNT(title) FROM challenge_1; + +--### Challenge 3 - Best Selling Authors + +CREATE TABLE challenge_3 + SELECT authors.au_id AS 'AUTHOR ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', titles.ytd_sales AS 'TOTAL' + FROM authors JOIN titleauthor + ON authors.au_id = titleauthor.au_id + JOIN titles + ON titleauthor.title_id = titles.title_id + GROUP BY authors.au_id + ORDER BY titles.ytd_sales DESC + LIMIT 3; + +SELECT * FROM challenge_3; + +--### Challenge 4 - Best Selling Authors Ranking + +CREATE TABLE challenge_4 + SELECT authors.au_id AS 'AUTHOR ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', titles.ytd_sales AS 'TOTAL' + FROM authors JOIN titleauthor + ON authors.au_id = titleauthor.au_id + JOIN titles + ON titleauthor.title_id = titles.title_id + GROUP BY authors.au_id + ORDER BY titles.ytd_sales DESC + ; + +SELECT * FROM challenge_4; + +--### Bonus Challenge - Most Profiting Authors + +CREATE TABLE bonus_challenge + SELECT authors.au_id AS 'AUTHOR ID', authors.au_lname AS 'LAST NAME', authors.au_fname AS 'FIRST NAME', SUM(titles.advance + (titles.royalty*titleauthor.royaltyper*titles.ytd_sales)) AS 'PROFIT' + FROM authors JOIN titleauthor + ON authors.au_id = titleauthor.au_id + JOIN titles + ON titleauthor.title_id = titles.title_id + GROUP BY authors.au_id + ORDER BY SUM(titles.advance + (titles.royalty*titleauthor.royaltyper*titles.ytd_sales)) DESC + LIMIT 3; + +SELECT * FROM bonus_challenge; \ No newline at end of file diff --git a/module-1/lab-resolving-git-conflicts/your-code/about-me.md b/module-1/lab-resolving-git-conflicts/your-code/about-me.md index 30a999d50..19694844d 100644 --- a/module-1/lab-resolving-git-conflicts/your-code/about-me.md +++ b/module-1/lab-resolving-git-conflicts/your-code/about-me.md @@ -1,7 +1,6 @@ -Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque viverra laoreet lorem et dapibus. Integer auctor dignissim egestas. Ut id purus neque. Pellentesque imperdiet lacus in libero laoreet, at tempus felis tristique. Cras fermentum erat a dui vulputate gravida. Nulla aliquet nisi interdum nulla pretium, ac vestibulum diam congue. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Phasellus lacus risus, sodales vitae viverra quis, maximus ac ipsum. Sed consequat viverra mattis. Curabitur iaculis varius mollis. - -Ut porttitor iaculis tellus bibendum euismod. Morbi porta, ante nec tempus porta, felis mi faucibus lacus, sed tristique purus nunc sed est. Aenean pulvinar urna ut lacus interdum aliquam. Pellentesque sit amet magna accumsan, sagittis metus a, volutpat velit. Mauris vitae ex vehicula, posuere nisi sed, sagittis nunc. Ut scelerisque, mi non tristique tristique, mi enim luctus nunc, eu mattis sem quam auctor nunc. Donec lobortis tellus eget blandit ultricies. Vivamus euismod metus eget leo blandit, at malesuada magna efficitur. Praesent sodales faucibus mi, ullamcorper ultrices orci. Vivamus maximus malesuada massa, nec placerat leo feugiat vel. Nam vitae eleifend enim. Nullam interdum ipsum velit, vitae faucibus lectus blandit euismod. Suspendisse ut malesuada ex. Nulla ultricies nisl et nisi rhoncus sollicitudin. Vestibulum maximus iaculis ligula, nec commodo nunc ullamcorper nec. Duis quis condimentum sapien. Cras vestibulum interdum felis eu auctor. Quisque semper, magna at dapibus faucibus, felis risus semper ligula, id aliquam lectus ligula vel nisi. In hac habitasse platea dictumst. Donec arcu sapien, suscipit ac dictum et, imperdiet id tortor. Maecenas ornare sodales interdum. Mauris dictum felis eu eros vestibulum cursus. Phasellus accumsan, turpis ut malesuada sollicitudin, augue leo venenatis ante, vel convallis tellus diam sit amet lacus. Aenean eu mauris eros. Praesent ante lacus, gravida sit amet tellus nec, laoreet ultrices lacus. Integer commodo semper vestibulum. Fusce felis massa, consectetur facilisis rutrum nec, pulvinar et nisi. Morbi fermentum ultricies tortor, vehicula ultrices eros elementum a. Duis ornare aliquam facilisis. Proin aliquam tincidunt odio vitae dignissim. Sed malesuada lacinia massa, nec blandit urna auctor elementum. Duis auctor non tortor in consequat. Mauris id vestibulum risus. In eget erat sed lacus efficitur viverra sed eu est. Aliquam interdum consequat molestie. Aliquam metus nisi, blandit non semper ut, blandit vel leo. Cras dictum turpis erat, sed iaculis ligula facilisis dapibus. Aliquam posuere dignissim fermentum. Praesent at neque sit amet lectus ornare iaculis. Curabitur id urna quis lorem varius ultrices eu sit amet sapien. Curabitur maximus volutpat suscipit. Proin imperdiet elementum lacus a eleifend. Sed tempor lacus posuere diam vehicula iaculis. +dddddd +>>>>>>> ca374493f4e058471605d2624eb5dcd47a865924 diff --git a/module-1/lab-string-operations/your-code/challenge-1.ipynb b/module-1/lab-string-operations/your-code/challenge-1.ipynb index 43020841b..a76656c3b 100644 --- a/module-1/lab-string-operations/your-code/challenge-1.ipynb +++ b/module-1/lab-string-operations/your-code/challenge-1.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -33,12 +33,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Durante un tiempo no estuvo segura de si su marido era su marido\n" + ] + } + ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n" + "# Your code here:\n", + "str_list_joined = ' '.join(str_list)\n", + "print(str_list_joined)" ] }, { @@ -50,12 +60,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Grocery list: bananas, bread, brownie mix, broccoli .\n" + ] + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "# Your code here:\n", + "food_list_filtered = [food.lower() for food in food_list]\n", + "food_list_joined = [ i for i in food_list_filtered if i.startswith('b')]\n", + "\n", + "print(\"Grocery list:\",', '.join(food_list_joined),\".\")\n", + "\n", + " \n", + "\n" ] }, { @@ -69,7 +94,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ @@ -78,6 +103,7 @@ "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", "radius = 4.5\n", + "pi = math.pi\n", "\n", "def area(x, pi = math.pi):\n", " # This function takes a radius and returns the area of a circle. We also pass a default value for pi.\n", @@ -89,8 +115,10 @@ " \n", " # Your code here:\n", " \n", + " r = float(radius)\n", " \n", - "# Your output string here:" + "# Your output string here:\n", + " print (\"The area of the circle with radius \" + str(r) + \" is: \" + str(pi * r**2))" ] }, { @@ -106,9 +134,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire,', 'Some', 'say', 'in', 'ice', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice,', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice']\n" + ] + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +156,8 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "print(poem.replace(\".\", \"\").split())" ] }, { @@ -132,9 +169,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 132, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['outstretched', 'grow', 'beheld', 'sunned', 'friend;', 'end', 'morning', 'told', 'day', 'was', 'wiles', 'smiles', 'foe:', 'that', 'beneath', 'did', 'till', 'veild', 'bright', 'not', 'pole;', 'mine', 'angry', 'tree', 'had', 'grew', 'with', 'when', 'tears:', 'foe', 'apple', 'garden', 'waterd', 'he', 'stole', 'shine', 'night', 'i', 'soft', 'fears', 'my', 'both', 'wrath', 'see;', 'deceitful', 'glad', 'bore', 'into', 'knew']\n" + ] + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +203,13 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "poem = poem.replace('.',\"\").replace(',',\"\").replace('&','').lower()\n", + "poemset = set(poem.split())\n", + "blacklistset = set(blacklist) \n", + "new_list = poemset.difference(blacklistset)\n", + "print(list(new_list))\n" ] }, { @@ -172,14 +223,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['T', 'P']\n" + ] + } + ], "source": [ "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "print(re.findall('[A-Z]',poem))" ] }, { @@ -191,13 +251,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 135, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "data1 = ''.join(data)\n", + "print(re.search('[\\d]',data1))" ] }, { @@ -213,13 +283,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 136, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n" + "# Your code here:\n", + "data2 = ''.join(data)\n", + "print(re.search('[\\d]+[a-z]',data2))" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -238,7 +325,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-string-operations/your-code/challenge-2.ipynb b/module-1/lab-string-operations/your-code/challenge-2.ipynb index 87c5656ef..43035616e 100644 --- a/module-1/lab-string-operations/your-code/challenge-2.ipynb +++ b/module-1/lab-string-operations/your-code/challenge-2.ipynb @@ -72,11 +72,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ - "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']" + "import os\n", + "docarray = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n" ] }, { @@ -88,12 +97,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 101, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ "corpus = []\n", - "\n", + "docs = [open(docarray[0]).read(),open(docarray[1]).read(),open(docarray[2]).read()]\n", + "for i in docs:\n", + " corpus.append(i)\n", + "print(corpus)\n", + " \n", "# Write your code here\n" ] }, @@ -101,14 +122,22 @@ "cell_type": "markdown", "metadata": {}, "source": [ - "Print `corpus`." + "#Print `corpus`." ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 103, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], "source": [ "print(corpus)" ] @@ -136,11 +165,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 154, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n" + ] + } + ], "source": [ - "# Write your code here" + "# Write your code here\n", + "docs = [open(docarray[0]).read(),open(docarray[1]).read(),open(docarray[2]).read()]\n", + "corpus = []\n", + "for i in docs:\n", + " corpus.append(i.lower().replace('.',\"\"))\n", + " \n", + "print(corpus)" ] }, { @@ -152,7 +195,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 155, "metadata": {}, "outputs": [], "source": [ @@ -172,11 +215,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 156, "metadata": {}, "outputs": [], "source": [ - "# Write your code here" + "# Write your code here\n", + "\n", + "bag_of_words.append(','.join(corpus).split()) \n" ] }, { @@ -192,10 +237,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 157, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[['ironhack', 'is', 'cool,i', 'love', 'ironhack,i', 'am', 'a', 'student', 'at', 'ironhack']]\n" + ] + } + ], "source": [ + "\n", "print(bag_of_words)" ] }, @@ -333,7 +387,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-tuple-set-dict/your-code/challenge-1.ipynb b/module-1/lab-tuple-set-dict/your-code/challenge-1.ipynb index 2e59d7714..520ef6b86 100644 --- a/module-1/lab-tuple-set-dict/your-code/challenge-1.ipynb +++ b/module-1/lab-tuple-set-dict/your-code/challenge-1.ipynb @@ -15,11 +15,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup = ('I', 'I')" ] }, { @@ -33,11 +34,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'I')\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(tup)" ] }, { @@ -55,13 +65,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k', 'r', 'o', 'n', 'h', 'a', 'c', 'k', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup=tup + (\"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "print(tup)\n", + "# Your explanation here\n", + "#tuple is not mutable" ] }, { @@ -79,13 +99,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, "outputs": [], "source": [ "# Your code here\n", - "\n", - "# Your explanation here\n" + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "# Your explanation here\n", + "#tuple is not mutable" ] }, { @@ -103,11 +124,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 36, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n')\n", + "('h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup = (\"I\", \"r\", \"o\", \"n\", \"h\", \"a\", \"c\", \"k\")\n", + "tup1 = (tup[0:4])\n", + "tup2 = (tup[-4:])\n", + "print(tup1)\n", + "print(tup2)\n" ] }, { @@ -121,11 +156,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('I', 'r', 'o', 'n', 'h', 'a', 'c', 'k')\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "tup3 = tup1 + tup2\n", + "print(tup3)" ] }, { @@ -137,11 +182,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n", + "4\n", + "8\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(len(tup1))\n", + "print(len(tup2))\n", + "print(len(tup3))" ] }, { @@ -153,11 +211,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(tup3.index(\"h\"))" ] }, { @@ -177,11 +244,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 57, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "Flase\n", + "True\n", + "Flase\n", + "Flase\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "letters = [\"a\", \"b\", \"c\", \"d\", \"e\"]\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(\"True\")\n", + " else:\n", + " print(\"Flase\")\n", + "\n", + "\n", + " \n" ] }, { @@ -193,14 +281,70 @@ "Print out the number of occurrence of each letter." ] }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a has occured 1 time(s).\n", + "c has occured 1 time(s).\n" + ] + } + ], + "source": [ + "# Your code here\n", + "for letter in letters:\n", + " if letter in tup3:\n", + " print(letter, \"has occured\", tup3.count(letter), \"time(s).\")" + ] + }, + { + "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": [] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ - "# Your code here\n" + "\n" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -219,7 +363,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-tuple-set-dict/your-code/challenge-2.ipynb b/module-1/lab-tuple-set-dict/your-code/challenge-2.ipynb index 41d691139..c0c80936b 100644 --- a/module-1/lab-tuple-set-dict/your-code/challenge-2.ipynb +++ b/module-1/lab-tuple-set-dict/your-code/challenge-2.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -38,11 +38,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[92, 99, 26, 77, 35, 87, 36, 52, 25, 24, 18, 37, 72, 54, 62, 68, 43, 93, 28, 48, 59, 49, 0, 9, 11, 47, 50, 23, 53, 91, 29, 42, 38, 4, 21, 34, 2, 76, 32, 79, 13, 1, 17, 16, 65, 71, 51, 55, 64, 97, 66, 33, 57, 6, 3, 60, 31, 46, 98, 61, 94, 20, 89, 39, 8, 67, 5, 56, 69, 14, 83, 40, 58, 75, 30, 84, 44, 80, 7, 41]\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "sample_list_1 = random.sample(range(100), k = 80)\n", + "print(sample_list_1)" ] }, { @@ -54,11 +64,25 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 14, 16, 17, 18, 20, 21, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 71, 72, 75, 76, 77, 79, 80, 83, 84, 87, 89, 91, 92, 93, 94, 97, 98, 99}\n", + "80\n" + ] + } + ], + "source": [ + "# Your code here\n", + "\n", + "set1 = set(sample_list_1)\n", + "print(set1)\n", + "print(len(set1))\n", + "#yes stil 80" ] }, { @@ -77,11 +101,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 33, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[54, 84, 76, 83, 39, 93, 53, 23, 7, 82, 97, 39, 97, 20, 95, 60, 56, 80, 76, 41, 29, 8, 51, 34, 25, 67, 11, 56, 13, 72, 13, 6, 74, 85, 78, 90, 10, 85, 92, 71, 7, 39, 55, 34, 81, 87, 78, 86, 79, 61, 81, 98, 85, 34, 52, 36, 58, 14, 53, 83, 47, 7, 59, 96, 61, 86, 46, 63, 54, 15, 68, 35, 19, 42, 92, 45, 39, 4, 34, 62]\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "sample_list_2 = [random.randint(0,100) for i in range (80)]\n", + "print(sample_list_2)" ] }, { @@ -93,11 +127,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "58\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set2 = set(sample_list_2)\n", + "print(len(set2))\n", + "#no longer 80" ] }, { @@ -109,11 +154,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 5, 9, 16, 17, 18, 21, 24, 26, 28, 30, 31, 32, 33, 37, 38, 40, 43, 44, 48, 49, 50, 57, 64, 65, 66, 69, 75, 77, 89, 91, 94, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set3 = set1.difference(set2)\n", + "print(set3)" ] }, { @@ -125,11 +180,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 38, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{96, 10, 74, 45, 78, 15, 81, 82, 19, 85, 86, 90, 95, 63}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set4 = set2.difference(set1)\n", + "print(set4)" ] }, { @@ -141,11 +206,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 39, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{4, 6, 7, 8, 11, 13, 14, 20, 23, 25, 29, 34, 35, 36, 39, 41, 42, 46, 47, 51, 52, 53, 54, 55, 56, 58, 59, 60, 61, 62, 67, 68, 71, 72, 76, 79, 80, 83, 84, 87, 92, 93, 97, 98}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set5 = set1.intersection(set2)\n", + "print(set5)" ] }, { @@ -165,11 +240,31 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Your code here\n" + "execution_count": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "58\n", + "36\n", + "14\n", + "44\n" + ] + } + ], + "source": [ + "# Your code here\n", + "print(len(set1))\n", + "print(len(set2))\n", + "print(len(set3))\n", + "print(len(set4))\n", + "print(len(set5))\n", + "\n", + "#len(set1) + len(set2) = len(3) + len(4) + len(5)*2\n", + "#80 + 58 = 36 + 14 + 44*2 " ] }, { @@ -181,11 +276,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set6 = {}\n", + "print(set6)" ] }, { @@ -197,11 +302,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 47, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "update expected at most 1 arguments, got 2", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[1;31m# Your code here\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mset6\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0mset6\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset3\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mset5\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset6\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: update expected at most 1 arguments, got 2" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "set6 = {}\n", + "set6.update(set3, set5)\n", + "print(set6)" ] }, { @@ -213,11 +333,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 66, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 13, 14, 16, 17, 18, 20, 21, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68, 69, 71, 72, 75, 76, 77, 79, 80, 83, 84, 87, 89, 91, 92, 93, 94, 97, 98, 99}\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(set1.difference(set6))\n" ] }, { @@ -229,11 +358,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 70, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(set2.issubset(set1))\n", + "print(set3.issubset(set1))" ] }, { @@ -247,11 +387,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 72, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "Set345Aggr = set3.union(set4, set5)\n", + "Set12Aggre = set1.union(set2)\n", + "print(Set345Aggr.issubset(Set12Aggre))" ] }, { @@ -263,11 +414,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 81, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "print(set1.pop())" ] }, { @@ -281,14 +441,36 @@ "```" ] }, + { + "cell_type": "code", + "execution_count": 88, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "{1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99}", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 2\u001b[0m \u001b[0mlist_to_remove\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[1;36m1\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m9\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m11\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m19\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m21\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m29\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m31\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m39\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m41\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m49\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m51\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m59\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m61\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m69\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m71\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m79\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m81\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m89\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m91\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;36m99\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[0mremovelist\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mset\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlist_to_remove\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 4\u001b[1;33m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdifference\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mset1\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mremove\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mremovelist\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m: {1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99}" + ] + } + ], + "source": [ + "# Your code here\n", + "list_to_remove = [1, 9, 11, 19, 21, 29, 31, 39, 41, 49, 51, 59, 61, 69, 71, 79, 81, 89, 91, 99]\n", + "removelist = set(list_to_remove)\n", + "print(set1.difference(set1.remove(removelist)))" + ] + }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], - "source": [ - "# Your code here\n" - ] + "source": [] } ], "metadata": { @@ -307,7 +489,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/lab-tuple-set-dict/your-code/challenge-3.ipynb b/module-1/lab-tuple-set-dict/your-code/challenge-3.ipynb index 7ab8ea5d6..c46a411f1 100644 --- a/module-1/lab-tuple-set-dict/your-code/challenge-3.ipynb +++ b/module-1/lab-tuple-set-dict/your-code/challenge-3.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -49,11 +49,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'dict_keys'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mword_freq2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mkey\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mkeys\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[1;32mif\u001b[0m \u001b[0mkey\u001b[0m \u001b[1;32min\u001b[0m \u001b[0mword_freq\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mword_freq2\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m;\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'dict_keys'" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "keys = [word_freq.keys()]\n", + "keys.sort()\n", + "\n", + "word_freq2 = {}\n", + "for key in keys:\n", + " if key in word_freq:\n", + " word_freq2[key] += 1;\n", + " else:\n", + " word_freq2[key] = 1;\n", + " print(word_freq2)\n", + "\n" ] }, { @@ -90,11 +113,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 45, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[('conversation', 1), (\"we're\", 1), ('plate', 1), ('sour', 1), ('jukebox', 1), ('taxi', 1), ('fast', 1), ('bag', 1), ('man', 1), ('going', 1), ('one', 1), ('backseat', 1), ('friends', 1), ('take', 1), ('play', 1), ('okay', 1), ('begin', 1), ('over', 1), ('just', 1), ('are', 1), ('tell', 1), ('drinking', 1), ('our', 1), ('where', 1), (\"i'll\", 1), ('all', 1), (\"isn't\", 1), ('make', 1), ('lover', 1), ('get', 1), ('radio', 1), ('give', 1), ('can', 1), ('club', 1), ('it', 1), ('out', 1), ('chance', 1), ('first', 1), ('table', 1), ('thrifty', 1), ('driver', 1), ('slow', 1), ('dance', 1), ('trust', 1), ('family', 1), ('week', 1), ('date', 1), ('leave', 1), ('at', 1), ('hand', 1), ('how', 1), ('eat', 1), ('about', 1), ('story', 1), ('sweet', 1), ('best', 1), ('let', 1), ('van', 1), ('shots', 1), ('place', 1), ('find', 1), ('kiss', 1), ('stop', 1), ('bar', 1), (\"don't\", 2), ('mind', 2), ('know', 2), ('so', 2), ('start', 2), ('boy', 2), ('girl', 2), ('singing', 2), ('doing', 2), ('somebody', 2), ('handmade', 2), ('may', 2), ('that', 2), ('much', 2), ('grab', 2), ('was', 2), ('say', 2), ('waist', 2), ('want', 2), (\"let's\", 2), ('not', 2), ('crazy', 2), ('go', 2), ('to', 2), ('fill', 2), ('hours', 2), ('push', 3), ('then', 3), ('put', 3), ('room', 3), ('magnet', 3), ('up', 3), ('pull', 3), ('last', 3), ('do', 3), ('smell', 3), ('although', 3), ('falling', 3), ('were', 3), ('night', 3), ('heart', 3), ('for', 3), ('bedsheets', 3), ('talk', 4), ('too', 5), ('is', 5), ('every', 6), ('new', 6), ('follow', 6), ('brand', 6), ('of', 6), ('i', 6), ('day', 6), ('lead', 6), ('shape', 6), ('discovering', 6), ('something', 6), ('we', 7), ('a', 8), ('like', 10), ('me', 10), ('now', 11), ('baby', 14), ('you', 16), ('be', 16), ('body', 17), ('the', 18), ('your', 21), ('with', 22), (\"i'm\", 23), ('and', 23), ('love', 25), ('in', 27), ('my', 33), ('come', 37), ('on', 40)]\n" + ] + }, + { + "ename": "TypeError", + "evalue": "update expected at most 1 arguments, got 2", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "\u001b[1;32m\u001b[0m in \u001b[0;36m\u001b[1;34m\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[0mword_freq2\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m{\u001b[0m\u001b[1;33m}\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[1;32mfor\u001b[0m \u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m \u001b[1;32min\u001b[0m \u001b[0msorted_tups\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 7\u001b[1;33m \u001b[0mword_freq2\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mupdate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m,\u001b[0m\u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m 8\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mword_freq2\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mTypeError\u001b[0m: update expected at most 1 arguments, got 2" + ] + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "import operator\n", + "sorted_tups = sorted(word_freq.items(), key=operator.itemgetter(1))\n", + "print(sorted_tups)\n", + "word_freq2 = {}\n", + "for x, y in sorted_tups:\n", + " word_freq2.update(x,y)\n", + " print(word_freq2)" ] }, { @@ -110,7 +159,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 46, "metadata": {}, "outputs": [], "source": [ @@ -132,11 +181,371 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
wordfreq
0love25
1conversation1
2every6
3we're1
4plate1
5sour1
6jukebox1
7now11
8taxi1
9fast1
10bag1
11man1
12push3
13baby14
14going1
15you16
16don't2
17one1
18mind2
19backseat1
20friends1
21then3
22know2
23take1
24play1
25okay1
26so2
27begin1
28start2
29over1
.........
110story1
111sweet1
112best1
113crazy2
114let1
115too5
116van1
117shots1
118go2
119to2
120a8
121my33
122is5
123place1
124find1
125shape6
126on40
127kiss1
128were3
129night3
130heart3
131for3
132discovering6
133something6
134be16
135bedsheets3
136fill2
137hours2
138stop1
139bar1
\n", + "

140 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " word freq\n", + "0 love 25\n", + "1 conversation 1\n", + "2 every 6\n", + "3 we're 1\n", + "4 plate 1\n", + ".. ... ...\n", + "135 bedsheets 3\n", + "136 fill 2\n", + "137 hours 2\n", + "138 stop 1\n", + "139 bar 1\n", + "\n", + "[140 rows x 2 columns]" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "df = pd.DataFrame({'word' : list(word_freq.keys()) , 'freq' : list(word_freq.values()) })\n", + "df" ] }, { @@ -150,11 +559,372 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 59, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
freqword
1208a
1091about
431all
963although
7223and
341are
1021at
1314baby
191backseat
101bag
1391bar
13416be
1353bedsheets
271begin
1121best
3017body
312boy
676brand
521can
631chance
551club
5637come
11conversation
1132crazy
841dance
901date
956day
1326discovering
923do
532doing
.........
51sour
282start
1381stop
1101story
1111sweet
751table
231take
1054talk
81taxi
361tell
682that
8518the
213then
791thrifty
1192to
1155too
871trust
703up
1161van
932waist
992want
812was
337we
31we're
891week
1283were
411where
5422with
1516you
9721your
\n", + "

140 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " freq word\n", + "120 8 a\n", + "109 1 about\n", + "43 1 all\n", + "96 3 although\n", + "72 23 and\n", + ".. ... ...\n", + "128 3 were\n", + "41 1 where\n", + "54 22 with\n", + "15 16 you\n", + "97 21 your\n", + "\n", + "[140 rows x 2 columns]" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "\n", + "df = df.sort_values('word')\n", + "df" ] }, { @@ -166,12 +936,379 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 60, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
freqword
1141let
871trust
111man
451make
461lover
1161van
981leave
1271kiss
251okay
321just
571it
421i'll
1041how
1031hand
141going
491give
471get
61jukebox
201friends
791thrifty
401our
361tell
81taxi
231take
751table
1111sweet
1101story
1381stop
171one
51sour
.........
746of
26every
956day
1326discovering
616new
676brand
786i
1256shape
646follow
1336something
1016lead
337we
1208a
9110me
5110like
711now
1314baby
1516you
13416be
3017body
8518the
9721your
5422with
7223and
5023i'm
025love
6527in
12133my
5637come
12640on
\n", + "

140 rows × 2 columns

\n", + "
" + ], + "text/plain": [ + " freq word\n", + "114 1 let\n", + "87 1 trust\n", + "11 1 man\n", + "45 1 make\n", + "46 1 lover\n", + ".. ... ...\n", + "0 25 love\n", + "65 27 in\n", + "121 33 my\n", + "56 37 come\n", + "126 40 on\n", + "\n", + "[140 rows x 2 columns]" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here\n" + "# Your code here\n", + "df = df.sort_values('freq')\n", + "df" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -190,7 +1327,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4, diff --git a/module-1/python-project/your-code/sample-code.ipynb b/module-1/python-project/your-code/sample-code.ipynb index a6f8a94d5..7b26b9630 100644 --- a/module-1/python-project/your-code/sample-code.ipynb +++ b/module-1/python-project/your-code/sample-code.ipynb @@ -6,20 +6,18 @@ "metadata": {}, "outputs": [], "source": [ - "# define rooms and items\n", - "\n", "couch = {\n", " \"name\": \"couch\",\n", " \"type\": \"furniture\",\n", "}\n", "\n", "door_a = {\n", - " \"name\": \"door a\",\n", + " \"name\": \"door A\",\n", " \"type\": \"door\",\n", "}\n", "\n", "key_a = {\n", - " \"name\": \"key for door a\",\n", + " \"name\": \"key for door A\",\n", " \"type\": \"key\",\n", " \"target\": door_a,\n", "}\n", @@ -30,27 +28,107 @@ "}\n", "\n", "game_room = {\n", - " \"name\": \"game room\",\n", + " \"name\": \"Game Room\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"Queen bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "door_b = {\n", + " \"name\": \"door B\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "key_b = {\n", + " \"name\": \"key for door B\",\n", + " \"type\": \"key\",\n", + " \"target\": door_b,\n", + "}\n", + "\n", + "door_c = {\n", + " \"name\": \"door C\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "bedroom_1 = {\n", + " \"name\": \"Bedroom 1\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "double_bed = {\n", + " \"name\": \"Double bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "key_c = {\n", + " \"name\": \"key for door C\",\n", + " \"type\": \"key\",\n", + " \"target\": door_c,\n", + "}\n", + "\n", + "dresser = {\n", + " \"name\": \"dresser\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "door_d = {\n", + " \"name\": \"door D\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "key_d = {\n", + " \"name\": \"key for door D\",\n", + " \"type\": \"key\",\n", + " \"target\": door_d,\n", + "}\n", + "\n", + "bedroom_2 = {\n", + " \"name\": \"Bedroom 2\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "dining_table = {\n", + " \"name\": \"Dining table\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "\n", + "\n", + "living_room = {\n", + " \"name\": \"Living Room\",\n", " \"type\": \"room\",\n", "}\n", "\n", "outside = {\n", - " \"name\": \"outside\"\n", + " \"name\": \"Outside\"\n", "}\n", "\n", - "all_rooms = [game_room, outside]\n", + "all_rooms = [game_room, bedroom_1, bedroom_2, living_room, outside]\n", "\n", - "all_doors = [door_a]\n", + "all_doors = [door_a, door_b, door_c, door_d]\n", "\n", "# define which items/rooms are related\n", "\n", "object_relations = {\n", - " \"game room\": [couch, piano, door_a],\n", - " \"piano\": [key_a],\n", - " \"outside\": [door_a],\n", - " \"door a\": [game_room, outside]\n", + " \"Game Room\": [couch, piano, door_a],\n", + " \"piano\": [key_a],\n", + " \"door A\": [game_room, bedroom_1],\n", + " \"Bedroom 1\": [door_a, queen_bed, door_b, door_c],\n", + " \"Queen bed\": [key_b],\n", + " \"door B\": [bedroom_1, bedroom_2],\n", + " \"door C\": [bedroom_1, living_room],\n", + " \"Bedroom 2\": [door_b, double_bed, dresser],\n", + " \"Double bed\": [key_c],\n", + " \"dresser\": [key_d],\n", + " \"Living Room\": [door_c, dining_table, door_d],\n", + " \"Outside\": [door_d],\n", + " \"door D\": [outside],\n", "}\n", "\n", + "\n", "# define game state. Do not directly change this dict. \n", "# Instead, when a new game starts, make a copy of this\n", "# dict and use the copy to store gameplay state. This \n", @@ -59,8 +137,8 @@ "INIT_GAME_STATE = {\n", " \"current_room\": game_room,\n", " \"keys_collected\": [],\n", - " \"target_room\": outside\n", - "}" + " \"target_room\": outside,\n", + "}\n" ] }, { @@ -81,7 +159,7 @@ " \"\"\"\n", " print(\"You wake up on a couch and find yourself in a strange house with no windows which you have never been to before. You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\")\n", " play_room(game_state[\"current_room\"])\n", - "\n", + " \n", "def play_room(room):\n", " \"\"\"\n", " Play a room. First check if the room being played is the target room.\n", @@ -178,21 +256,46 @@ "output_type": "stream", "text": [ "You wake up on a couch and find yourself in a strange house with no windows which you have never been to before. You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\n", - "You are now in game room\n", - "What would you like to do? Type 'explore' or 'examine'?explore\n", - "You explore the room. This is game room. You find couch, piano, door a\n", - "You are now in game room\n", - "What would you like to do? Type 'explore' or 'examine'?examine\n", - "What would you like to examine?door a\n", - "You examine door a. It is locked but you don't have the key.\n", - "You are now in game room\n", + "You are now in Game Room\n", "What would you like to do? Type 'explore' or 'examine'?examine\n", "What would you like to examine?piano\n", - "You examine piano. You find key for door a.\n", - "You are now in game room\n", + "You examine piano. You find key for door A.\n", + "You are now in Game Room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door A\n", + "You examine door A. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in Bedroom 1\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?Queen bed\n", + "You examine Queen bed. You find key for door B.\n", + "You are now in Bedroom 1\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door B\n", + "You examine door B. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in Bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?Double bed\n", + "You examine Double bed. You find key for door C.\n", + "You are now in Bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?dresser\n", + "You examine dresser. You find key for door D.\n", + "You are now in Bedroom 2\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door B\n", + "You examine door B. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in Bedroom 1\n", "What would you like to do? Type 'explore' or 'examine'?examine\n", - "What would you like to examine?door a\n", - "You examine door a. You unlock it with a key you have.\n", + "What would you like to examine?door C\n", + "You examine door C. You unlock it with a key you have.\n", + "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", + "You are now in Living Room\n", + "What would you like to do? Type 'explore' or 'examine'?examine\n", + "What would you like to examine?door D\n", + "You examine door D. You unlock it with a key you have.\n", "Do you want to go to the next room? Ener 'yes' or 'no'yes\n", "Congrats! You escaped the room!\n", "\n", @@ -206,6 +309,21 @@ "\n", "\n", "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", "\n" ] } @@ -213,9 +331,20 @@ "source": [ "game_state = INIT_GAME_STATE.copy()\n", "\n", + "def current_inventory():\n", + " print(\"You have keys:\", game_state[\"keys_collected\"])\n", + "current_inventory\n", + "\n", "start_game()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, { "cell_type": "code", "execution_count": null, @@ -240,7 +369,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.2" + "version": "3.7.3" } }, "nbformat": 4,