Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 59 additions & 4 deletions Week-02/beginner/beginner_exercise.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,17 @@
"source": [
"# Solve Alphabet slices here. \n",
"## Extra Credit: Do this without 'hard coding' the alpahbet.\n",
"import string\n",
"\n",
"# Get the first 10 letters of the alphabet using slicing\n",
"alphabet = list(string.ascii_lowercase[:10])\n",
"\n",
"# First 3 letters\n",
"print(alphabet[:3])\n",
"\n",
"# 3 letters from the middle (e.g., starting at index 4)\n",
"middle_index = len(alphabet) // 2 # middle is index 5 for 10 letters\n",
"print(alphabet[middle_index - 1: middle_index + 2])\n",
"\n"
]
},
Expand All @@ -38,7 +48,13 @@
"outputs": [],
"source": [
"# Solve rapper names here\n",
"rappers = ['lil wayne', 'nicki minaj', 'drake']\n"
"rappers = ['lil wayne', 'nicki minaj', 'drake']\n",
"upper_rappers = []\n",
"for name in rappers:\n",
" upper_name = name.title()\n",
" upper_rappers.append(name.title())\n",
"print(upper_names)\n",
"\n"
]
},
{
Expand Down Expand Up @@ -109,7 +125,14 @@
"source": [
"# Solve problem here:\n",
"\n",
"names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n"
"names = [\"Michele\", \"Robin\", \"Sara\", \"Michele\"]\n",
"def remove_duplicates(names):\n",
" new_list = []\n",
" for name in names:\n",
" if name not in new_list:\n",
" new_list.append(name)\n",
" return new_list\n",
"\n"
]
},
{
Expand All @@ -131,7 +154,16 @@
"outputs": [],
"source": [
"# Solve problem here:\n",
"input_list = [5, 10, 99, 20, 25]"
"input_list = [5, 10, 99, 20, 25] \n",
"new_list = []\n",
"\n",
"first = input_list[0]\n",
"last = input_list[-1]\n",
"\n",
"new_list.append(first)\n",
"new_list.append(last)\n",
"\n",
"print(new_list) # Output: [5, 25]\n"
]
},
{
Expand Down Expand Up @@ -159,6 +191,20 @@
"\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):\n",
" biggest = a\n",
" if a < b:\n",
" biggest = b\n",
" if b > c:\n",
" biggest = b\n",
" else:\n",
" biggest = c\n",
" elif a >= b:\n",
" if a > c:\n",
" biggest = a\n",
" else:\n",
" biggest = c\n",
" return biggest\n",
" "
]
},
Expand Down Expand Up @@ -189,7 +235,16 @@
"metadata": {},
"outputs": [],
"source": [
"# Solve Problem fizzbuzz here:\n"
"# Solve Problem fizzbuzz here:\n",
"def fizzbuzz(num):\n",
" if num % 3 == 0 and num % 5 == 0:\n",
" return 'fizzbuzz'\n",
" elif num % 3 == 0:\n",
" return 'fizz'\n",
" elif num % 5 == 0:\n",
" return 'buzz'\n",
" else:\n",
" return None"
]
}
],
Expand Down