diff --git a/AD450_math.py b/AD450_math.py new file mode 100644 index 0000000..357720a --- /dev/null +++ b/AD450_math.py @@ -0,0 +1,5 @@ +def add(num1, num2): + return num1 + num2 + +def multiply(num1, num2): + return num1 * num2 \ No newline at end of file diff --git a/week_2_intro_ipython.ipynb b/week_2_intro_ipython.ipynb index 1a469f7..01bc8d3 100644 --- a/week_2_intro_ipython.ipynb +++ b/week_2_intro_ipython.ipynb @@ -24,12 +24,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 22, "metadata": { "id": "BQybla17FRh5" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My name is Julien.\n", + "I am a student at North Seattle College\n" + ] + } + ], + "source": [ + "name = \"Julien\"\n", + "print(\"My name is \" + name + \".\\nI am a student at North Seattle College\")" + ] }, { "cell_type": "markdown", @@ -43,12 +55,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": { "id": "P7QDyWncFRh8" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My phone number is 2069991111\n" + ] + } + ], + "source": [ + "phone = 2069991111\n", + "print(\"My phone number is \" + str(phone))" + ] }, { "cell_type": "markdown", @@ -62,12 +85,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "metadata": { "id": "OnOau948FRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello my name is Julien and my phone number is 206-999-1111\n" + ] + } + ], + "source": [ + "name = \"Julien\"\n", + "phone_number = \"206-999-1111\"\n", + "\n", + "print(f\"Hello my name is {name} and my phone number is {phone_number}\")" + ] }, { "cell_type": "markdown", @@ -82,12 +118,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": { "id": "5x2rIFzRFRh9" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I graduate in June of 2027\n" + ] + } + ], + "source": [ + "month, year = \"June\", 2027\n", + "print(f\"I graduate in {month} of {year}\")" + ] }, { "cell_type": "markdown", @@ -109,12 +156,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "metadata": { "id": "OkyeAVPXFRh-" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "58.5\n" + ] + } + ], + "source": [ + "ans = 12 * 5 - 3 / 2\n", + "print(ans)\n", + "# it is float because there are trailing decimals\n" + ] }, { "cell_type": "markdown", @@ -136,12 +195,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "metadata": { "id": "Lo-LEy8bKYmG" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "31 days\n" + ] + } + ], + "source": [ + "month = \"October\"\n", + "\n", + "if month == \"October\":\n", + " print(\"31 days\")\n", + "else:\n", + " print(\"30 days\")\n", + " \n" + ] }, { "cell_type": "markdown", @@ -157,12 +232,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": { "id": "qscUkh813QKH" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "between 100 and 150\n" + ] + } + ], + "source": [ + "num = 140\n", + "\n", + "if num > 150:\n", + " print(\"greater than 150\")\n", + "elif num > 100:\n", + " print(\"between 100 and 150\")\n", + "else:\n", + " print(\"less than 100\")" + ] }, { "cell_type": "markdown", @@ -177,12 +269,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 29, "metadata": { "id": "1vxg4nMbFRh_" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number is divisible by 5 and 10\n", + "Number is divisible by 7 or 2\n" + ] + } + ], + "source": [ + "num = 70 \n", + "if num % 5 == 0 and num % 10 == 0:\n", + " print(\"Number is divisible by 5 and 10\")\n", + "\n", + "if num % 7 == 0 or num % 2 == 0:\n", + " print(\"Number is divisible by 7 or 2\")" + ] }, { "cell_type": "markdown", @@ -195,12 +303,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 30, "metadata": { "id": "JY_Ci5v-FRiA" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "7\n", + "14\n", + "21\n", + "28\n", + "35\n", + "42\n", + "49\n", + "56\n", + "63\n", + "70\n", + "77\n", + "84\n", + "91\n", + "98\n" + ] + } + ], + "source": [ + "for i in range(0, 100):\n", + " if i % 7 == 0:\n", + " print(i)" + ] }, { "cell_type": "markdown", @@ -213,12 +347,30 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "id": "4a1D64hpFRiA" - }, - "outputs": [], - "source": [] + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 3 6 9 \n", + "18\n" + ] + } + ], + "source": [ + "i = 0\n", + "sums = 0\n", + "nums = \"\"\n", + "while i < 10: \n", + " if i % 3 == 0:\n", + " nums += str(i) + \" \"\n", + " sums += i\n", + " i += 1\n", + "print(nums)\n", + "print(sums)\n" + ] }, { "cell_type": "markdown", @@ -241,12 +393,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": { "id": "ntBnYxzi1RPc" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Set: 1\n", + "Set: 2\n", + "Student 0\n", + "Student 1\n", + "Student 2\n", + "Student 3\n", + "Student 4\n", + "Set: 3\n", + "Set: 4\n", + "Student 0\n", + "Student 1\n", + "Student 2\n", + "Student 3\n", + "Student 4\n", + "Set: 5\n" + ] + } + ], + "source": [ + "set1 = {1, 2, 3, 4, 5}\n", + "set2 = set(set1)\n", + "set3 = set(set1)\n", + "set4 = set(set1)\n", + "set5 = set(set1) \n", + "\n", + "\n", + "for i in range(1, 6):\n", + " print(f\"Set: {i}\")\n", + " if i % 2 == 0:\n", + " for j in range(len(set1)):\n", + " print(f\"Student {j}\")\n", + " " + ] }, { "cell_type": "markdown", @@ -259,12 +447,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 40, "metadata": { "id": "lppms8ctzfRI" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hogwarts\n", + "s\n" + ] + } + ], + "source": [ + "school = \"Hogwarts\"\n", + "first = school[0:3]\n", + "second = school[3:8]\n", + "print(first + second)\n", + "print(school[-1])" + ] }, { "cell_type": "markdown", @@ -280,12 +483,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": { "id": "zw2NezoM0zfl" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Thor is a character in the Marvel Cinematic Universe\n", + "She-Hulk is a character in the Marvel Cinematic Universe\n", + "Loki is a character in the Marvel Cinematic Universe\n" + ] + } + ], + "source": [ + "chars = [\"Thor\", \"She-Hulk\", \"Loki\"]\n", + "for char in chars:\n", + " print(char +\" is a character in the Marvel Cinematic Universe\")" + ] }, { "cell_type": "markdown", @@ -299,12 +516,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": { "id": "rbyZif9a1b2V" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "janurary has 31 days\n", + "february has 28 days\n", + "march has 31 days\n", + "april has 30 days\n", + "may has 31 days\n", + "june has 30 days\n" + ] + } + ], + "source": [ + "months = [[\"janurary\", 31], [\"february\", 28], [\"march\", 31], [\"april\", 30], [\"may\", 31], [\"june\", 30]]\n", + "for i in range(len(months)):\n", + " print(f\"{months[i][0]} has {months[i][1]} days\")\n" + ] }, { "cell_type": "markdown", @@ -321,12 +555,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": { "id": "p0YE0nqs4Hcz" }, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Breed': 'Corgi', 'Age': 13, 'Type': 'Cattle herding'}\n", + "Corgi\n", + "The Corgi is expected to live about 13 years\n" + ] + } + ], + "source": [ + "dog = {\n", + " \"Breed\": \"Corgi\",\n", + " \"Age\": 13,\n", + " \"Type\": \"Cattle herding\"\n", + "}\n", + "print(dog)\n", + "print(dog[\"Breed\"])\n", + "print(f\"The {dog['Breed']} is expected to live about {dog['Age']} years\")" + ] }, { "cell_type": "markdown", @@ -337,9 +590,20 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 44, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import AD450_math\n", "\n", @@ -359,9 +623,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'AD450_math' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[1]\u001b[39m\u001b[32m, line 2\u001b[39m\n\u001b[32m 1\u001b[39m \u001b[38;5;66;03m# Cell with import error\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m2\u001b[39m \u001b[43mAD450_math\u001b[49m.multiply(\u001b[32m2\u001b[39m, \u001b[32m2\u001b[39m)\n", + "\u001b[31mNameError\u001b[39m: name 'AD450_math' is not defined" + ] + } + ], "source": [ "# Cell with import error\n", "AD450_math.multiply(2, 2)" @@ -369,18 +645,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Reload cell" + "# Reload cell\n", + "import importlib\n", + "import AD450_math\n", + "\n", + "importlib.reload(AD450_math)\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Cell with correct output \n", "AD450_math.multiply(2, 2)" @@ -400,29 +702,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 48, "metadata": {}, "outputs": [], "source": [ - "# Create a" + "# Create a\n", + "a = 1 " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n" + ] + } + ], "source": [ - "# Print a" + "# Print a\n", + "print(a)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 50, "metadata": {}, "outputs": [], "source": [ - "# Set a to 4" + "# Set a to 4\n", + "a = 4 " ] } ], @@ -431,7 +744,7 @@ "provenance": [] }, "kernelspec": { - "display_name": "my_env_2", + "display_name": "base", "language": "python", "name": "python3" }, @@ -445,7 +758,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.16" + "version": "3.13.5" } }, "nbformat": 4,