diff --git a/Week-03/intermediate/intermediate-exercise.ipynb b/Week-03/intermediate/DN_intermediate-exercise.ipynb similarity index 51% rename from Week-03/intermediate/intermediate-exercise.ipynb rename to Week-03/intermediate/DN_intermediate-exercise.ipynb index 40041d1..ee15fab 100644 --- a/Week-03/intermediate/intermediate-exercise.ipynb +++ b/Week-03/intermediate/DN_intermediate-exercise.ipynb @@ -22,8 +22,22 @@ "cell_type": "code", "execution_count": null, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "datetime: 2025-08-06 11:48:15\n" + ] + } + ], + "source": [ + "import datetime as dt\n", + "\n", + "currentTime = dt.datetime.now()\n", + "formattedTime = currentTime.strftime(\"%Y-%m-%d %H:%M:%S\")\n", + "print(f\"date time: {formattedTime}\")" + ] }, { "cell_type": "markdown", @@ -35,10 +49,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "78.53981633974483\n" + ] + } + ], + "source": [ + "import math\n", + "def area(radius):\n", + " return radius * radius * math.pi\n", + "\n", + "radius = 5\n", + "print(area(radius))\n" + ] }, { "cell_type": "markdown", @@ -54,10 +83,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "def duplicate(inputList):\n", + " if len(inputList) != len(set(inputList)):\n", + " return False\n", + " else: return True\n", + "\n", + "inputList = [2, 4, 5, 6, 7, 5]\n", + "print(duplicate(inputList)) " + ] }, { "cell_type": "markdown", @@ -73,10 +118,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'D': 74, 'W': 63, 'A': 211, 'Y': 44, 'N': 165, 'E': 274, ' ': 522, 'M': 77, 'I': 185, 'C': 60, 'H': 122, 'L': 126, 'R': 152, 'T': 180, 'J': 8, '.': 26, '(': 12, 'B': 59, 'O': 145, 'S': 152, 'P': 39, '2': 24, '7': 7, ',': 37, '1': 28, '9': 16, '8': 6, ')': 12, '[': 14, ']': 14, 'K': 13, 'F': 44, 'G': 53, 'X': 5, 'U': 66, 'V': 20, '3': 2, '4': 4, '5': 5, '6': 3, '0': 36, '\\n': 6, '-': 6, ';': 1, '!': 1, '—': 1}\n" + ] + } + ], "source": [ + "from collections import defaultdict\n", + "\n", + "char_count = defaultdict(int)\n", + "file_object = open(\"/workspaces/2025-python-summer-prep/Week-03/intermediate/data/lil-wayne.txt\")\n", + "text = file_object.read().upper()\n", + "for char in text:\n", + " char_count[char] += 1\n", + "char_count = dict(char_count)\n", + "print(char_count)\n", "\n" ] }, @@ -89,10 +151,68 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "' ': 522\n", + "'E': 274\n", + "'A': 211\n", + "'I': 185\n", + "'T': 180\n", + "'N': 165\n", + "'R': 152\n", + "'S': 152\n", + "'O': 145\n", + "'L': 126\n", + "'H': 122\n", + "'M': 77\n", + "'D': 74\n", + "'U': 66\n", + "'W': 63\n", + "'C': 60\n", + "'B': 59\n", + "'G': 53\n", + "'Y': 44\n", + "'F': 44\n", + "'P': 39\n", + "',': 37\n", + "'0': 36\n", + "'1': 28\n", + "'.': 26\n", + "'2': 24\n", + "'V': 20\n", + "'9': 16\n", + "'[': 14\n", + "']': 14\n", + "'K': 13\n", + "'(': 12\n", + "')': 12\n", + "'J': 8\n", + "'7': 7\n", + "'8': 6\n", + "'\n", + "': 6\n", + "'-': 6\n", + "'X': 5\n", + "'5': 5\n", + "'4': 4\n", + "'6': 3\n", + "'3': 2\n", + "';': 1\n", + "'!': 1\n", + "'—': 1\n" + ] + } + ], + "source": [ + "sorted_chars = sorted(char_count.items(), key=lambda item: item[1], reverse=True)\n", + "for char, count in sorted_chars:\n", + " print(f\"'{char}': {count}\")" + ] }, { "cell_type": "markdown", @@ -112,11 +232,24 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 1, 2, 5, 8, 13, 21, 63]\n" + ] + } + ], "source": [ - "list1 = [1, 1, 2, 3, 5, 8, 13, 21]" + "list1 = [1, 1, 2, 3, 5, 8, 13, 21]\n", + "\n", + "removed = list1.pop(3)\n", + "newNum = removed * list1[-1]\n", + "list1.append(newNum)\n", + "print(list1)" ] }, { @@ -131,11 +264,24 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 6, 9, 15, 21]\n" + ] + } + ], "source": [ - "original_list = [2, 3, 6, 8, 9, 15, 19, 21]" + "original_list = [2, 3, 6, 8, 9, 15, 19, 21]\n", + "newList = []\n", + "for i in original_list:\n", + " if i % 3 == 0:\n", + " newList.append(i)\n", + "print(newList)" ] }, { @@ -147,11 +293,21 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[21, 19, 15, 9, 8, 6, 3, 2]\n" + ] + } + ], "source": [ - "original_list = [2, 3, 6, 8, 9, 15, 19, 21]" + "original_list = [2, 3, 6, 8, 9, 15, 19, 21]\n", + "original_list.reverse()\n", + "print(original_list)" ] }, { @@ -165,11 +321,24 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49]\n" + ] + } + ], "source": [ - "original_list = [1, 2, 3, 4, 5, 6, 7]\n" + "original_list = [1, 2, 3, 4, 5, 6, 7]\n", + "new_list = []\n", + "for i in original_list:\n", + " squareNum = i **2\n", + " new_list.append(squareNum)\n", + "print(new_list)" ] }, { @@ -194,12 +363,26 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 69, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 400\n", + "20 300\n", + "30 200\n", + "40 100\n" + ] + } + ], "source": [ "list1 = [10, 20, 30, 40]\n", - "list2 = [100, 200, 300, 400]" + "list2 = [100, 200, 300, 400]\n", + "list2.reverse()\n", + "for i in range(len(list1)):\n", + " print(list1[i], list2[i])" ] }, { @@ -214,11 +397,22 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I', 'love', 'data', 'science', '!']\n" + ] + } + ], "source": [ - "list_of_strings = ['I', 'love', '', '', 'data', '', 'science', '!']\n" + "list_of_strings = ['I', 'love', '', '', 'data', '', 'science', '!']\n", + "while \"\" in list_of_strings:\n", + " list_of_strings.remove(\"\")\n", + "print(list_of_strings)" ] }, { @@ -234,11 +428,27 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], "source": [ - "sample_dict = {'a': 100, 'b': 999, 'c': 300}\n" + "sample_dict = {'a': 100, 'b': 999, 'c': 300}\n", + "val = sample_dict.values()\n", + "check = 0\n", + "for i in val:\n", + " if i == 999:\n", + " check += 1\n", + " if check > 0:\n", + " print(True)\n", + " break\n" ] }, { @@ -251,9 +461,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "closing parenthesis ')' does not match opening parenthesis '[' (1985171303.py, line 4)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[82]\u001b[39m\u001b[32m, line 4\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mif message in [\"Arrr!\"):\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m closing parenthesis ')' does not match opening parenthesis '['\n" + ] + } + ], "source": [ "greeting = \"Hello, possible pirate! What's the password?\"\n", "password = 'admin'\n", @@ -266,9 +485,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "cannot assign to expression here. Maybe you meant '==' instead of '='? (718890877.py, line 3)", + "output_type": "error", + "traceback": [ + " \u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[86]\u001b[39m\u001b[32m, line 3\u001b[39m\n\u001b[31m \u001b[39m\u001b[31mnumber-of-pieces = 100\u001b[39m\n ^\n\u001b[31mSyntaxError\u001b[39m\u001b[31m:\u001b[39m cannot assign to expression here. Maybe you meant '==' instead of '='?\n" + ] + } + ], "source": [ "pages = 457\n", "word_per_page == 250\n", @@ -280,17 +508,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Greetings, hater of pirates!\n" + ] + } + ], + "source": [ + "greeting = \"Hello, possible pirate! What's the password?\"\n", + "password = 'admin'\n", + "message = greeting+password\n", + "if message in [\"Arrr!\"]:\n", + "\tprint(\"Go away, pirate.\")\n", + "elif message not in [\"Arrr!\"]:\n", + "\tprint(\"Greetings, hater of pirates!\")" + ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 90, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11425.0\n" + ] + } + ], + "source": [ + "pages = 457\n", + "word_per_page = 250\n", + "number_of_pieces = 100\n", + "\n", + "each_chunk = (457 * 250)/10\n", + "print(each_chunk)" + ] }, { "cell_type": "code", @@ -315,18 +574,9 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 91, "metadata": {}, - "outputs": [ - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/Users/zacharydesario/opt/anaconda3/lib/python3.8/site-packages/pandas/core/computation/expressions.py:20: UserWarning: Pandas requires version '2.7.3' or newer of 'numexpr' (version '2.7.1' currently installed).\n", - " from pandas.core.computation.check import NUMEXPR_INSTALLED\n" - ] - } - ], + "outputs": [], "source": [ "import pandas as pd" ] @@ -340,10 +590,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 97, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "df = pd.read_csv('/workspaces/2025-python-summer-prep/Week-03/intermediate/data/titanic.csv')" + ] }, { "cell_type": "markdown", @@ -376,7 +628,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -390,7 +642,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.5" + "version": "3.12.3" } }, "nbformat": 4,