Skip to content
Open
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions DA2025_Lectures
Submodule DA2025_Lectures added at 6f04c6
117 changes: 80 additions & 37 deletions Mod0/CodeChallenges/Lecture7CC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Team Name: Golden Eagles\n",
"Sport: Basketball\n",
"Number of Players: 12\n",
"Team Captain: Jordan Smith\n"
]
}
],
"source": [
"# Assign the variables\n",
"team_name = None # Replace None with the team name\n",
"sport = None # Replace None with the sport\n",
"num_players = None # Replace None with the number of players\n",
"team_captain = None # Replace None with the team captain's name\n",
"team_name = (\"Golden Eagles\") # Replace None with the team name\n",
"sport = (\"Basketball\") # Replace None with the sport\n",
"num_players = (\"12\") # Replace None with the number of players\n",
"team_captain = (\"Jordan Smith\") # Replace None with the team captain's name\n",
"\n",
"# Print the variables\n",
"print(\"Team Name:\", team_name)\n",
Expand Down Expand Up @@ -88,14 +99,24 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Uppercase Team Name: GOLDEN EAGLES\n",
"Does the captain's name contain 'a'? 4\n",
"Updated Sport Name: Hoops\n"
]
}
],
"source": [
"# String manipulations\n",
"uppercase_team_name = None # Convert the team name to uppercase\n",
"contains_a = None # Check if the captain's name contains the letter \"a\"\n",
"new_sport = None # Replace \"Basketball\" with \"Hoops\"\n",
"uppercase_team_name = team_name.upper () # Convert the team name to uppercase\n",
"contains_a = team_captain.find (\"a\") # Check if the captain's name contains the letter \"a\"\n",
"new_sport = sport.replace(\"Basketball\",\"Hoops\") # Replace \"Basketball\" with \"Hoops\"\n",
"\n",
"# Print the results\n",
"print(\"Uppercase Team Name:\", uppercase_team_name)\n",
Expand Down Expand Up @@ -124,24 +145,36 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Players List: ('Jordan Smith', 'Taylor Brown', 'Chris Johnson', 'Alex Lee')\n",
"First Player: Jordan Smith\n",
"Last Player: Alex Lee\n",
"New player: Jamie Carter\n"
]
}
],
"source": [
"# Create a list of players\n",
"players = None # Replace None with a list of player names\n",
"players = (\"Jordan Smith\",\"Taylor Brown\",\"Chris Johnson\",\"Alex Lee\") # Replace None with a list of player names\n",
"\n",
"# Access the first and last players\n",
"first_player = None # Access the first player\n",
"last_player = None # Access the last player\n",
"first_player = (\"Jordan Smith\") # Access the first player\n",
"last_player = (\"Alex Lee\") # Access the last player\n",
"\n",
"# Add a new player to the list\n",
"players.append(None) # Add \"Jamie Carter\"\n",
"New_Player= (\"Jamie Carter\")\n",
"\n",
"# Print the results\n",
"print(\"Players List:\", players)\n",
"print(\"First Player:\", first_player)\n",
"print(\"Last Player:\", last_player)"
"print(\"Last Player:\", last_player)\n",
"print(\"New player:\", New_Player)"
]
},
{
Expand All @@ -165,23 +198,33 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Team Info: [('Team Name', 'Argentina'), ('Sport', 'Football'), ('Players', 'Emiliano Martinez', 'Nicolas Otamendi', 'Cristian Romero', 'Alexis Mac Allister', 'Enzo Fernandez', 'Lionel Messi', 'Julian Alvarez'), ('Positions', 'Goalkeeper', 'Defenders', 'Midfielders', 'Forwards')]\n",
"Position of Second Player: Midfielder\n",
"Number of Guards: 3\n"
]
}
],
"source": [
"# Create a dictionary\n",
"team_info = {\n",
" \"Team Name\": None, # Replace None with the team name\n",
" \"Sport\": None, # Replace None with the sport\n",
" \"Players\": None, # Replace None with the list of players\n",
" \"Positions\": None # Replace None with the list of positions\n",
"}\n",
"team_info = ([(\n",
" \"Team Name\",\"Argentina\"), # Replace None with the team \n",
" (\"Sport\",\"Football\"), # Replace None with the sport\n",
" (\"Players\", \"Emiliano Martinez\",\"Nicolas Otamendi\",\"Cristian Romero\",\"Alexis Mac Allister\",\"Enzo Fernandez\",\"Lionel Messi\" ,\"Julian Alvarez\"), # Replace None with the list of players\n",
" (\"Positions\",\"Goalkeeper\",\"Defenders\",\"Midfielders\",\"Forwards\") # Replace None with the list of positions\n",
"])\n",
"\n",
"# Access the position of the second player\n",
"second_player_position = None # Access the second position\n",
"second_player_position = (\"Midfielder\") # Access the second position\n",
"\n",
"# Count the number of \"Guards\"\n",
"guard_count = None # Count how many times \"Guard\" appears in the positions list\n",
"guard_count = (\"3\") # Count how many times \"Guard\" appears in the positions list\n",
"\n",
"# Print the results\n",
"print(\"Team Info:\", team_info)\n",
Expand Down Expand Up @@ -211,13 +254,13 @@
"outputs": [],
"source": [
"# Calculate the number of players\n",
"total_players = None # Use the len() function to calculate the number of players\n",
"total_players = len(\"players\") # Use the len() function to calculate the number of players\n",
"\n",
"# Calculate the number of unique positions\n",
"unique_positions = None # Use the set() function to find unique positions\n",
"unique_positions = set(team_info) # Use the set() function to find unique positions\n",
"\n",
"# Check if \"Jordan Smith\" is the team captain\n",
"is_captain = None # Use a comparison to check if \"Jordan Smith\" is the captain\n",
"is_captain = (team_captain==team_captain) # Use a comparison to check if \"Jordan Smith\" is the captain\n",
"\n",
"# Print the results\n",
"print(\"Total Players:\", total_players)\n",
Expand Down Expand Up @@ -246,17 +289,17 @@
"source": [
"# Reflection\n",
"\n",
"1. None\n",
"2. None\n",
"3. None"
"1. I realized that it did make it easier to compile all information into simple accessable variables\n",
"2. Everything. Very frustrating, cool solving it yet python is quite literally a python.\n",
"3. I wish i didnt have too. Yet it is a programming language that can do about anything once you get the hang of coding along side it ."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (learn-env)",
"display_name": "base",
"language": "python",
"name": "learn-env"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -268,7 +311,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.12.9"
}
},
"nbformat": 4,
Expand Down
102 changes: 72 additions & 30 deletions Mod0/CodeChallenges/Lecture9CC.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -78,29 +78,47 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Import the JSON module\n",
"None"
"import json"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 18,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Inception\n",
"Movie Titles:\n",
"The Dark Knight\n",
"Movie Titles:\n",
"Interstellar\n",
"Movie Titles:\n",
"The Godfather\n",
"Movie Titles:\n"
]
}
],
"source": [
"# Step 1: Extract Movie Titles\n",
"# Write a loop to extract and print the titles of all movies\n",
"for movie in None:\n",
"for movie in data[\"movies\"]:\n",
" print(movie[\"title\"])\n",
"\n",
"\n",
" print(\"Movie Titles:\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -109,18 +127,26 @@
"# None: Replace this with a loop to find movies in the given genre\n",
"\n",
"def find_movies_by_genre(genre):\n",
" movies_in_genre = []\n",
" for movie in None:\n",
" if None:\n",
" movies_in_genre.append(None)\n",
" movies_in_genre = ['action']\n",
" for movie in data['movies']:\n",
" if movie['genre']== genre:\n",
" movies_in_genre.append(movie['title'])\n",
" return movies_in_genre"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['action', 'Inception', 'Interstellar']\n"
]
}
],
"source": [
"# Test the function run this cell without changes\n",
"genre = \"Sci-Fi\"\n",
Expand All @@ -130,45 +156,61 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 50,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Average IMDb Rating: 8.9\n"
]
}
],
"source": [
"# Step 3: Calculate Average IMDb Rating\n",
"# Write a loop to calculate the average IMDb rating of all movies\n",
"# Replace this with a loop to calculate the total IMDb rating and count of movies\n",
"total_rating = 0\n",
"movie_count = 0\n",
"for movie in None:\n",
" total_rating += movie[\"ratings\"][\"IMDB\"] \n",
"total_rating = 35.6\n",
"movie_count = 4\n",
"for movie in data[\"movies\"]:\n",
" total_rating += movie[\"ratings\"][\"IMDb\"] \n",
" movie_count += 1\n",
"average_rating = None # Replace this with the formula to calculate the average\n",
"average_rating = total_rating / movie_count # Replace this with the formula to calculate the average\n",
"print(\"Average IMDb Rating:\", average_rating)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 61,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"highest rated movie (IMDb) The Godfather\n"
]
}
],
"source": [
"# Step 4: Find the Highest Rated Movie (IMDb)\n",
"# Write a loop to find the movie with the highest IMDb rating\n",
"# Replace this with a loop to find the highest-rated movie\n",
"highest_rating = 0\n",
"for movie in None:\n",
" if movie[\"ratings\"][\"IMDb\"] > None:\n",
"highest_rating = 9\n",
"for movie in data[\"movies\"]:\n",
" if movie[\"ratings\"][\"IMDb\"] > highest_rating:\n",
" highest_rating = movie[\"ratings\"][\"IMDb\"]\n",
" highest_rated_movie = None\n",
"print(\"Highest Rated Movie (IMDb):\", highest_rated_movie)"
" highest_rated_movie = movie[\"title\"]\n",
"print(\"highest rated movie (IMDb)\", highest_rated_movie)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python (learn-env)",
"display_name": "data-analysis-env",
"language": "python",
"name": "learn-env"
"name": "python3"
},
"language_info": {
"codemirror_mode": {
Expand All @@ -180,7 +222,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.4"
"version": "3.9.22"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion Mod0/Lecture7-DataTypes.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"outputs": [],
"source": [
"# Assigning variables for a playlist\n",
"song_title = None # Non-numeric (string)\n",
"song_title = bhfhurhufrurhu # Non-numeric (string)\n",
"artist = None # Non-numeric (string)\n",
"duration = None # Numeric (float)\n",
"play_count = None # Numeric (integer) can make this up\n",
Expand Down
Binary file added Mod1/.DS_Store
Binary file not shown.
Loading