From 8f3f9db9109ae5a704c237642dfa33d2718ed546 Mon Sep 17 00:00:00 2001 From: KDawTech <146153229+KDawTech@users.noreply.github.com> Date: Sun, 3 Aug 2025 04:58:19 +0000 Subject: [PATCH 1/3] Completed Week 2 homework --- homeworks/kd_week2_hw.ipynb | 260 ++++++++++++++++++++++++++++++++++++ 1 file changed, 260 insertions(+) create mode 100644 homeworks/kd_week2_hw.ipynb diff --git a/homeworks/kd_week2_hw.ipynb b/homeworks/kd_week2_hw.ipynb new file mode 100644 index 0000000..71a02c7 --- /dev/null +++ b/homeworks/kd_week2_hw.ipynb @@ -0,0 +1,260 @@ +{ + "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", + "\n" + alphabet=list(string.ascii_lowercase)[:10] + print(alpahbet[:3]) + print(alpahbet[4:7]) + ] + }, + { + "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" + title_case_rappers = [name.title() for name in rappers] + print(title_case_rappers) + ] + }, + { + "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", + " pass # replace this with your code\n", + " # return something" + return lst % 2 == 0 + #testing + print(even_odd(4)) # True +print(even_odd(7)) # False + ] + }, + { + "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 = ???\n", + "list_avg = ???\n", + "\n", + "\n", + "# Keep this as your last line in this cell.\n", + "print(list_sum, list_average)" + + total = 0 +for num in my_list: + total += num +avg = total / len(my_list) + +print(total, avg) + +# Without loop +total2 = sum(my_list) +avg2 = total2 / len(my_list) + +print(total2, avg2) + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve problem here:\n", + "\n", + "names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n" + unique_names = list(set(names)) +print(unique_names) + ] + }, + { + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Solve problem here:\n", + "input_list = [5, 10, 99, 20, 25]" + result = [input_list[0], input_list[-1]] +print(result) + ] + }, + { + "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": null, + "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", + " " + ] + def my_max(a, b, c): + if a > b and a > c: + return a + elif b > a and b > c: + return b + else: + return c + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Test to see if your function works properly.\n", + "my_max(1, 5, 10)" + print(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" + def fizzbuzz(n): + if n % 3 == 0 and n % 5 == 0: + return 'fizzbuzz' + elif n % 3 == 0: + return 'fizz' + elif n % 5 == 0: + return 'buzz' + else: + return None + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} From f17e7eefbe3ca04c3e31473461001a302ef15a57 Mon Sep 17 00:00:00 2001 From: KDawTech <146153229+KDawTech@users.noreply.github.com> Date: Sun, 3 Aug 2025 05:14:47 +0000 Subject: [PATCH 2/3] Completed week 2 homework --- homeworks/kd_week2_hw.ipynb | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/homeworks/kd_week2_hw.ipynb b/homeworks/kd_week2_hw.ipynb index 71a02c7..3229ff2 100644 --- a/homeworks/kd_week2_hw.ipynb +++ b/homeworks/kd_week2_hw.ipynb @@ -21,9 +21,14 @@ "## Extra Credit: Do this without 'hard coding' the alpahbet.\n", "\n", "\n" - alphabet=list(string.ascii_lowercase)[:10] - print(alpahbet[:3]) - print(alpahbet[4:7]) + import string + + alphabet = string.ascii_lowercase + + print(alphabet[:10]) + print(alphabet[:3]) + print(alphabet[4:7]) + ] }, { @@ -42,7 +47,7 @@ "source": [ "# Solve rapper names here\n", "rappers = ['lil wayne', 'nicki minaj', 'drake']\n" - title_case_rappers = [name.title() for name in rappers] + title_case_rappers = [name.title() for name in rappers] print(title_case_rappers) ] }, @@ -69,7 +74,7 @@ return lst % 2 == 0 #testing print(even_odd(4)) # True -print(even_odd(7)) # False + print(even_odd(7)) # False ] }, { @@ -98,17 +103,17 @@ print(even_odd(7)) # False "print(list_sum, list_average)" total = 0 -for num in my_list: + for num in my_list: total += num -avg = total / len(my_list) + avg = total / len(my_list) -print(total, avg) + print(total, avg) # Without loop -total2 = sum(my_list) -avg2 = total2 / len(my_list) + total2 = sum(my_list) + avg2 = total2 / len(my_list) -print(total2, avg2) + print(total2, avg2) ] }, { @@ -133,7 +138,7 @@ print(total2, avg2) "\n", "names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n" unique_names = list(set(names)) -print(unique_names) + print(unique_names) ] }, { @@ -157,7 +162,7 @@ print(unique_names) "# Solve problem here:\n", "input_list = [5, 10, 99, 20, 25]" result = [input_list[0], input_list[-1]] -print(result) + print(result) ] }, { From 59d14de6ab549ecafae60911d21e5a11d72366a7 Mon Sep 17 00:00:00 2001 From: KDawTech <146153229+KDawTech@users.noreply.github.com> Date: Sun, 3 Aug 2025 05:23:06 +0000 Subject: [PATCH 3/3] Completed week 2 homework --- homeworks/kd_week2_hw.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/homeworks/kd_week2_hw.ipynb b/homeworks/kd_week2_hw.ipynb index 3229ff2..e5b1f45 100644 --- a/homeworks/kd_week2_hw.ipynb +++ b/homeworks/kd_week2_hw.ipynb @@ -21,7 +21,7 @@ "## Extra Credit: Do this without 'hard coding' the alpahbet.\n", "\n", "\n" - import string + #import string (not sure how to import here since i used on vs code) alphabet = string.ascii_lowercase @@ -47,8 +47,8 @@ "source": [ "# Solve rapper names here\n", "rappers = ['lil wayne', 'nicki minaj', 'drake']\n" - title_case_rappers = [name.title() for name in rappers] - print(title_case_rappers) + real_rappers = [name.title() for name in rappers] + print(real_rappers) ] }, {