diff --git a/Week-03/intermediate/intermediate-lecture.ipynb b/Week-03/intermediate/intermediate-lecture.ipynb index 8a5e799..71284a2 100644 --- a/Week-03/intermediate/intermediate-lecture.ipynb +++ b/Week-03/intermediate/intermediate-lecture.ipynb @@ -645,7 +645,7 @@ }, { "cell_type": "code", - "execution_count": 81, + "execution_count": null, "metadata": {}, "outputs": [ { @@ -748,7 +748,7 @@ }, { "cell_type": "code", - "execution_count": 79, + "execution_count": null, "metadata": {}, "outputs": [ { diff --git a/homeworks/WX_Week3_HW.ipynb b/homeworks/WX_Week3_HW.ipynb new file mode 100644 index 0000000..fef7aad --- /dev/null +++ b/homeworks/WX_Week3_HW.ipynb @@ -0,0 +1,575 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Googling how to do something is NOT cheating. \n", + "# Googling how to do figure something out is ENCOURAGED. " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #1 Figure out how to print the current date and time. \n", + "The solution should be in this format: 2021-08-05 11:56:30 (YYYY-MM-DD HH:MM:SS)\n", + "\n", + "Hint: You're going to have to import a library" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2025-08-04 20:35:07\n" + ] + } + ], + "source": [ + "from datetime import datetime\n", + "from zoneinfo import ZoneInfo\n", + "\n", + "ny_time = datetime.now(ZoneInfo('America/New_York'))\n", + "print(ny_time.strftime(\"%Y-%m-%d %H:%M:%S\"))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #2 Write a function that accepts the radius of a circle and returns the area of a circle. \n", + "The function for the area of a circle is pi * radius squared. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.566370614359172\n" + ] + } + ], + "source": [ + "from math import pi\n", + "\n", + "def circle_area(radius):\n", + " return pi * radius ** 2\n", + "\n", + "print(circle_area(2))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #3 Write a function that takes a list of numbers and returns True of all number in the list are unique and returns False if the list contains duplicate numbers. \n", + "* Hint, maybe think of using a set()\n", + "\n", + "Input: input_list = [2,4,5,5,7,9]\n", + "\n", + "Expected Output: False" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ] + } + ], + "source": [ + "def unique(lst):\n", + " if len(lst) == len(set(lst)):\n", + " return True\n", + " return False\n", + "\n", + "print(unique([1,2,3]))\n", + "print(unique([1,3,3]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #4 Write a Python program to count the number of each character of a given text of a text file.\n", + "* Use the text file called 'lil-wayne.txt' in the data folder. \n", + "* Convert all the characters to uppercase first, then count them. \n", + "* Use a dictionary in which the keys of the dictionary are the characters, and the values are the counts of that character. \n", + "\n", + "Expected Result: `{'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, '\"': 8, \"'\": 3, 'β€”': 1}`" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "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": [ + "with open('lil-wayne.txt', 'r') as file:\n", + " content = file.read()\n", + "\n", + "letters = [char.upper() for char in content]\n", + "\n", + "dict = {}\n", + "\n", + "for letter in letters:\n", + " dict[letter] = dict.get(letter, 0) + 1\n", + "\n", + "print(dict)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# 4.5 Figure out how to sort the dictionary to find which character appears the most." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[(' ', 522), ('E', 274), ('A', 211), ('I', 185), ('T', 180), ('N', 165), ('R', 152), ('S', 152), ('O', 145), ('L', 126), ('H', 122), ('M', 77), ('D', 74), ('U', 66), ('W', 63), ('C', 60), ('B', 59), ('G', 53), ('Y', 44), ('F', 44), ('P', 39), (',', 37), ('0', 36), ('1', 28), ('.', 26), ('2', 24), ('V', 20), ('9', 16), ('[', 14), (']', 14), ('K', 13), ('(', 12), (')', 12), ('J', 8), ('7', 7), ('8', 6), ('\\n', 6), ('-', 6), ('X', 5), ('5', 5), ('4', 4), ('6', 3), ('3', 2), (';', 1), ('!', 1), ('β€”', 1)]\n" + ] + } + ], + "source": [ + "sorted_dict = sorted(dict.items(), key = lambda x: x[1], reverse = True)\n", + "print(sorted_dict)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #5 Using the list below...\n", + "* Remove the fourth number from the list.\n", + "* Take that number you just removed and multiply the last number of the list by that number. \n", + "* Append that number to the end of the list.\n", + "* Print the list\n", + "\n", + "INPUT: [1, 1, 2, 3, 5, 8, 13, 21]\n", + "\n", + "EXPECTED OUTPUT: [1, 1, 2, 5, 8, 13, 21, 63]\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "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]\n", + "temp = list1[3]\n", + "\n", + "for i in range(3, len(list1) - 1):\n", + " list1[i] = list1[i+1]\n", + "\n", + "list1[-1] = temp * list1[-1]\n", + "print(list1)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #6 Using the list below, make a new list that contains only the numbers from the original list that are divisible by three.\n", + "\n", + "* Input: original_list = [2, 3, 6, 8, 9, 15, 19, 21]\n", + "* Expected new list: [3, 6, 9, 15, 21]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[3, 6, 9, 15, 21]\n" + ] + } + ], + "source": [ + "original_list = [2, 3, 6, 8, 9, 15, 19, 21]\n", + "div_3 = []\n", + "\n", + "for num in original_list:\n", + " if num % 3 == 0:\n", + " div_3.append(num)\n", + "\n", + "print(div_3)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #7 Reverse the list below" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "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]\n", + "original_list.reverse()\n", + "\n", + "print(original_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #8 Using the list below, turn every item of the list into its square. \n", + "* Input original_list = [1, 2, 3, 4, 5, 6, 7]\n", + "* Expected new_list: [1, 4, 9, 16, 25, 36, 49]\n" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "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", + "\n", + "for i in range(len(original_list)):\n", + " original_list[i] = original_list[i] ** 2\n", + "\n", + "print(original_list)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #9 Given a two Python list. Iterate both lists simultaneously such that list1 should display item in original order and list2 in reverse order.\n", + "Given input:\n", + "```\n", + "list1 = [10, 20, 30, 40]\n", + "list2 = [100, 200, 300, 400]\n", + "```\n", + "\n", + "Expected Output:\n", + "```\n", + "10 400\n", + "20 300\n", + "30 200\n", + "40 100\n", + "```" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "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]\n", + "\n", + "list1.extend(list2)\n", + "\n", + "left, right = 0, len(list1) - 1\n", + "\n", + "while left < right:\n", + " print(list1[left], list1[right], sep = \" \")\n", + " left += 1\n", + " right -= 1" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #10 Remove empty strings from the list of strings.\n", + "Input: `list_of_strings = ['I', 'love', '', '', 'data', '', 'science', '!']`\n", + "\n", + "Expected Output: `['I', 'love', 'data', 'science', '!']`" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['I', 'love', 'data', 'science', '!']\n" + ] + } + ], + "source": [ + "list_of_strings = ['I', 'love', '', '', 'data', '', 'science', '!']\n", + "res = []\n", + "\n", + "for word in list_of_strings:\n", + " if word != '':\n", + " res.append(word)\n", + "\n", + "print(res)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## #11 Check if the value 999 exists in the dicitionary below. If so, print true, if not print false.\n", + "\n", + "Input: sample_dict = {'a': 100, 'b': 999, 'c': 300}\n", + "\n", + "Expected Output: True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "sample_dict = {'a': 100, 'b': 999, 'c': 300}\n", + "\n", + "def check(dict):\n", + " if 999 in sample_dict.values():\n", + " return True\n", + " return False\n", + "\n", + "print(check(sample_dict))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# #12 Fix all the follow broken code snippets below\n", + "(I got these examples from a great website, I will reference them later because they have the answers on them.)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "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", + "else:\n", + "\tprint(\"Greetings, hater of pirates!\")" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1142.5\n" + ] + } + ], + "source": [ + "pages = 457\n", + "word_per_page = 250\n", + "number_of_pieces = 100\n", + "\n", + "each_chunk = 457 * 250 / 100\n", + "print(each_chunk)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Extra Credit" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Using pandas, read the csv file in the data folder called `titianic.csv` and store it as a variable named `df`." + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "ename": "ModuleNotFoundError", + "evalue": "No module named 'pandas'", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mModuleNotFoundError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[41]\u001b[39m\u001b[32m, line 1\u001b[39m\n\u001b[32m----> \u001b[39m\u001b[32m1\u001b[39m \u001b[38;5;28;01mimport\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpandas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[38;5;28;01mas\u001b[39;00m\u001b[38;5;250m \u001b[39m\u001b[34;01mpd\u001b[39;00m\n", + "\u001b[31mModuleNotFoundError\u001b[39m: No module named 'pandas'" + ] + } + ], + "source": [ + "import pandas as pd" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## I know we didn't cover this, but figure out how to find the mean age of the age column in your dataframe. " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## What was the oldest and youngest ages on the titanic?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## How many people embarked from station 'S'?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".venv", + "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 +} diff --git a/homeworks/lil-wayne.txt b/homeworks/lil-wayne.txt new file mode 100644 index 0000000..48bb8c0 --- /dev/null +++ b/homeworks/lil-wayne.txt @@ -0,0 +1,7 @@ +Dwayne Michael Carter Jr. (born September 27, 1982),[2] known professionally as Lil Wayne, is an American rapper, singer, songwriter and record executive.. He is commonly regarded as one of the most influential hip hop artists of his generation,[3] and often cited as one of the greatest rappers of all time.[4][5] His career began in 1995, at the age of 12, when he was signed by rapper Birdman, joining Cash Money Records as the youngest member of the label.[6] From then on, Wayne was the flagship artist of Cash Money Records before ending his association with the company in June 2018.[7] + +In 1995, Wayne was put in a duo with label-mate B.G. (at the time known as Lil Doogie) and they recorded an album, True Story, released that year, although Wayne (at the time known as Baby D) only appeared on three tracks.[8] Wayne and B.G. soon joined the southern hip hop group Hot Boys, with Cash Money label-mates Juvenile and Turk in 1997; they released their debut album Get It How U Live! in October that year. The Hot Boys became popular following the release of the album Guerrilla Warfare (1999) and the song Bling Bling. + +Lil Waynes solo debut album Tha Block Is Hot (1999) was his solo breakthrough, and he reached higher popularity with his fourth album Tha Carter (2004) and fifth album Tha Carter II (2005), as well as several mixtapes and collaborations throughout 2006 and 2007. He gained more prominence within the music industry with his sixth album Tha Carter III (2008), with first-week sales of over one million copies in the US. The album won the Grammy Award for Best Rap Album and included successful singles A Milli, Got Money (featuring T-Pain), and Lollipop (featuring Static Major)β€”the latter being his first single to reach number one on the Billboard Hot 100. In February 2010, Wayne released his seventh studio album, Rebirth, which experimented with rap rock and was met with generally negative reviews. A month later in March 2010, Lil Wayne began serving an 8-month jail sentence in New York after being convicted of criminal possession of a weapon stemming from an incident in July 2007. His eighth studio album I Am Not a Human Being (2010) was released during his incarceration, while his 2011 album Tha Carter IV was released following his release. Tha Carter IV sold 964,000 copies in its first week in the United States.[9] His twelfth studio album Tha Carter V was released in 2018 after multiple delays. Waynes thirteenth album, Funeral, was released in early 2020.[10] + +Lil Wayne has sold over 120 million records worldwide, including more than 20 million albums and 70 million digital tracks in the United States, making him one of the worlds best-selling music artists.[11][12][13] He has won five Grammy Awards, 11 BET Awards, four Billboard Music Awards, two MTV Video Music Awards and eight NAACP Image Awards. On September 27, 2012, he became the first male artist to surpass Elvis Presley with the most entries on the Billboard Hot 100, with 109 songs.[14][15] Lil Wayne also currently serves as the chief executive officer (CEO) of his own label, Young Money Entertainment. \ No newline at end of file