From e35a06c8ecb04b16efd65a4c831507483149df75 Mon Sep 17 00:00:00 2001 From: Dang Nguyen <159592918+NathanNguyen21@users.noreply.github.com> Date: Fri, 1 Aug 2025 09:52:33 +0000 Subject: [PATCH 1/3] Q1, Q2, Q3, Q4, Q5, Q6, Q8 --- .../intermediate/intermediate_exercise.ipynb | 79 +++++++++++++++---- 1 file changed, 64 insertions(+), 15 deletions(-) diff --git a/Week-02/intermediate/intermediate_exercise.ipynb b/Week-02/intermediate/intermediate_exercise.ipynb index b5e834b..d1024e9 100644 --- a/Week-02/intermediate/intermediate_exercise.ipynb +++ b/Week-02/intermediate/intermediate_exercise.ipynb @@ -20,7 +20,13 @@ "# Solve Alphabet slices here. \n", "## Extra Credit: Do this without 'hard coding' the alpahbet.\n", "\n", - "\n" + "#alp = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"]\n", + "\n", + "alp = (\"abcdefghij\")\n", + "threeAlp = slice(3)\n", + "print(alp[threeAlp])\n", + "midAlp = slice(3,6)\n", + "print(alp[midAlp])\n" ] }, { @@ -38,7 +44,12 @@ "outputs": [], "source": [ "# Solve rapper names here\n", - "rappers = ['lil wayne', 'nicki minaj', 'drake']\n" + "rappers = ['lil wayne', 'nicki minaj', 'drake']\n", + "capRappers = []\n", + "for i in rappers:\n", + " capName = i.title()\n", + " capRappers.append(capName)\n", + "print(capRappers)" ] }, { @@ -59,7 +70,10 @@ "# Solve problem here\n", "\n", "def even_odd(lst):\n", - " pass # replace this with your code\n", + " if lst % 2 == 0:\n", + " return True\n", + " else:\n", + " return False\n", " # return something" ] }, @@ -81,12 +95,15 @@ "# Solve problem here:\n", "\n", "my_list = [1, 5, 10, 55, 88, 44, 42, 50, 20, 38]\n", - "list_sum = ???\n", - "list_avg = ???\n", + "#list_sum = sum(my_list)\n", + "#list_avg = list_sum / len(my_list)\n", "\n", + "for i in my_list:\n", + " list_sum += i\n", + " list_avg = list_sum / len(my_list)\n", "\n", "# Keep this as your last line in this cell.\n", - "print(list_sum, list_average)" + "print(list_sum, list_avg)" ] }, { @@ -103,13 +120,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Robin', 'Sara', 'Michele'}\n" + ] + } + ], "source": [ "# Solve problem here:\n", "\n", - "names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n" + "names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n", + "dupName = set(names)\n", + "print(dupName)" ] }, { @@ -126,12 +153,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 32, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5, 25]\n" + ] + } + ], "source": [ "# Solve problem here:\n", - "input_list = [5, 10, 99, 20, 25]" + "input_list = [5, 10, 99, 20, 25]\n", + "output_list = []\n", + "output_list.append(input_list[0])\n", + "output_list.append(input_list[-1])\n", + "print(output_list)" ] }, { @@ -189,13 +228,23 @@ "metadata": {}, "outputs": [], "source": [ - "# Solve Problem fizzbuzz here:\n" + "# Solve Problem fizzbuzz here:\n", + "num = int(input(\"Input a number:\"))\n", + "print(num)\n", + "if num % 3 == 0:\n", + " print(\"fizz\")\n", + "if num % 5 == 0:\n", + " print(\"buzz\")\n", + "if num % 5 == 0 & num & 3 == 0:\n", + " print(\"fizzbuzz\")\n", + "else:\n", + " print(\"None\")" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -209,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.12.4" + "version": "3.12.1" } }, "nbformat": 4, From 452a298b7eeb01fb24bd3c4f3ff32967a42eb38e Mon Sep 17 00:00:00 2001 From: Dang Nguyen <159592918+NathanNguyen21@users.noreply.github.com> Date: Fri, 1 Aug 2025 09:57:47 +0000 Subject: [PATCH 2/3] Q8 --- .../intermediate/intermediate_exercise.ipynb | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/Week-02/intermediate/intermediate_exercise.ipynb b/Week-02/intermediate/intermediate_exercise.ipynb index d1024e9..87a2784 100644 --- a/Week-02/intermediate/intermediate_exercise.ipynb +++ b/Week-02/intermediate/intermediate_exercise.ipynb @@ -190,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, "outputs": [], "source": [ @@ -198,14 +198,26 @@ "\n", "def my_max(a, b, c):\n", " # Fill in your code below and return max value of a, b, c\n", - " " + " maxNum = max(a,b,c)\n", + " return maxNum" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 35, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Test to see if your function works properly.\n", "my_max(1, 5, 10)" From 49fba50a06f0ed83215bdbc7b502cf8adb4b3a40 Mon Sep 17 00:00:00 2001 From: Dang Nguyen <159592918+NathanNguyen21@users.noreply.github.com> Date: Sat, 6 Sep 2025 01:29:18 +0000 Subject: [PATCH 3/3] 100% exercise --- .../dangnguyen_intermediate_exercise.ipynb | 278 ++++++++++++++++++ 1 file changed, 278 insertions(+) create mode 100644 Week-02/intermediate/dangnguyen_intermediate_exercise.ipynb diff --git a/Week-02/intermediate/dangnguyen_intermediate_exercise.ipynb b/Week-02/intermediate/dangnguyen_intermediate_exercise.ipynb new file mode 100644 index 0000000..87a2784 --- /dev/null +++ b/Week-02/intermediate/dangnguyen_intermediate_exercise.ipynb @@ -0,0 +1,278 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## ❌ DO NOT EDIT - MAKE A COPY\n", + "# Q1: Alphabet Slices\n", + "* Store the first ten letters of the alphabet in a list.\n", + "* Use a slice to print out the first three letters of the alphabet.\n", + "* Use a slice to print out any three letters from the middle of your list." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve Alphabet slices here. \n", + "## Extra Credit: Do this without 'hard coding' the alpahbet.\n", + "\n", + "#alp = [\"a\",\"b\",\"c\",\"d\",\"e\",\"f\",\"g\",\"h\",\"i\",\"j\"]\n", + "\n", + "alp = (\"abcdefghij\")\n", + "threeAlp = slice(3)\n", + "print(alp[threeAlp])\n", + "midAlp = slice(3,6)\n", + "print(alp[midAlp])\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q2: Covert all the rapper names to title case and save them into a new different list. \n", + "Example: **lil wayne** becomes **Lil Wayne**" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve rapper names here\n", + "rappers = ['lil wayne', 'nicki minaj', 'drake']\n", + "capRappers = []\n", + "for i in rappers:\n", + " capName = i.title()\n", + " capRappers.append(capName)\n", + "print(capRappers)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q3: Write a function that takes a number and returns:\n", + "* True if the input number is even.\n", + "* False if the input number is odd." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve problem here\n", + "\n", + "def even_odd(lst):\n", + " if lst % 2 == 0:\n", + " return True\n", + " else:\n", + " return False\n", + " # return something" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q4: Find the sum and the average of this list of numbers.\n", + "\n", + "Try doing this using a loop. Then try doing this without using a loop. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve problem here:\n", + "\n", + "my_list = [1, 5, 10, 55, 88, 44, 42, 50, 20, 38]\n", + "#list_sum = sum(my_list)\n", + "#list_avg = list_sum / len(my_list)\n", + "\n", + "for i in my_list:\n", + " list_sum += i\n", + " list_avg = list_sum / len(my_list)\n", + "\n", + "# Keep this as your last line in this cell.\n", + "print(list_sum, list_avg)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q5: \n", + "## Write a function that takes a list and returns a new list that has all the duplicates removed.\n", + "\n", + "Example input and expected output:\n", + "- input = `[\"Michele\", \"Robin\", \"Sara\", \"Michele\"]`\n", + "- expected output = `['Michele', 'Robin', 'Sara']`\n" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'Robin', 'Sara', 'Michele'}\n" + ] + } + ], + "source": [ + "# Solve problem here:\n", + "\n", + "names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n", + "dupName = set(names)\n", + "print(dupName)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q6: Write a function that takes a list of numbers \n", + "(for example, `a = [5, 10, 15, 20, 25]`) and returns a new list of only the first and last elements of the given list.\n", + "\n", + "Example input and expected output:\n", + "- input = `[5, 10, 15, 20, 25]`\n", + "- expected output = `[5, 25]`" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[5, 25]\n" + ] + } + ], + "source": [ + "# Solve problem here:\n", + "input_list = [5, 10, 99, 20, 25]\n", + "output_list = []\n", + "output_list.append(input_list[0])\n", + "output_list.append(input_list[-1])\n", + "print(output_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q7: \n", + "## Implement a function that takes as input three variables, and returns the largest of the three. \n", + "### Try doing this without using the `max()` function!\n", + "\n", + "_**Note:** all three input numbers will always be different, no need to account for a tie._\n", + "\n", + "Example input and expected output:\n", + "- input: `your_function(1, 5, 10)`\n", + "- expected output: `10`" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve Problem here:\n", + "\n", + "def my_max(a, b, c):\n", + " # Fill in your code below and return max value of a, b, c\n", + " maxNum = max(a,b,c)\n", + " return maxNum" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 35, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test to see if your function works properly.\n", + "my_max(1, 5, 10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Q8: Write a function that takes a number as input and returns the following:\n", + "* If the input is divisible by three, return `'fizz'`\n", + "* If the input is divisible by five, return `'buzz'`\n", + "* If the input is divisible by three and by five, return `'fizzbuzz'`\n", + "* If the input is not divisible by three or five, return `None`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve Problem fizzbuzz here:\n", + "num = int(input(\"Input a number:\"))\n", + "print(num)\n", + "if num % 3 == 0:\n", + " print(\"fizz\")\n", + "if num % 5 == 0:\n", + " print(\"buzz\")\n", + "if num % 5 == 0 & num & 3 == 0:\n", + " print(\"fizzbuzz\")\n", + "else:\n", + " print(\"None\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.1" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}