3.2 Popcorn Hacks
Mihir's Submission for Hacks from Lesson
Popcorn Hack 1
Create a list of data that could work with your GitHub Pages Blog Topic. For example, if your blog was about movies from different genres, make a list of movies for every genre.
# Define a dictionary with Liverpool FC players categorized by positions
liverpool_fc = {
"Forwards": ["Mohamed Salah", "Darwin Núñez", "Diogo Jota", "Luis Díaz"],
"Midfielders": ["Alexis Mac Allister", "Dominik Szoboszlai", "Curtis Jones", "Ryan Gravenberch"],
"Defenders": ["Virgil van Dijk", "Ibrahima Konaté", "Trent Alexander-Arnold", "Andrew Robertson"],
"Goalkeepers": ["Alisson Becker", "Caoimhin Kelleher"]
}
# New function to print Liverpool FC players by position
def print_liverpool_fc(team):
for position, players in team.items():
print(f"\n{position}:")
for player in players:
print(f" - {player}")
# Call the function to display Liverpool FC players
print_liverpool_fc(liverpool_fc)
Forwards:
- Mohamed Salah
- Darwin Núñez
- Diogo Jota
- Luis Díaz
Midfielders:
- Alexis Mac Allister
- Dominik Szoboszlai
- Curtis Jones
- Ryan Gravenberch
Defenders:
- Virgil van Dijk
- Ibrahima Konaté
- Trent Alexander-Arnold
- Andrew Robertson
Goalkeepers:
- Alisson Becker
- Caoimhin Kelleher
OPTIONAL Popcorn Hack 2
Try creating a dictionary for your github homepage that contains what was within each sprint. For example, in Sprint 1, we had frontend development, github pages playgroud, and javascript playground.
# Define a dictionary with sprints as keys and details as a nested dictionary
sprints = {
'Sprint1': {
'Tasks': ['Frontend Development', 'Github Pages Playground', 'Javascript Playground'],
'Duration': '2 weeks',
'Team Members': ['Mihir', 'Ansh', 'Derek', 'Pradyun']
},
'Sprint2': {
'Tasks': ['Big Ideas 3.1','Big Ideas 3.2','Big Ideas 3.3','Big Ideas 3.4','Big Ideas 3.5','Big Ideas 3.6','Big Ideas 3.7','Big Ideas 3.8','Big Ideas 3.10'],
'Duration': '1 week',
'Team Members': ['Mihir', 'Ansh', 'Derek', 'Pradyun']
}
}
# Function to print details about the sprints
def print_sprint_details(sprint_data):
for sprint, details in sprint_data.items():
print(f"\n{sprint}:")
for key, value in details.items():
print(f"{key}: {value}")
# Call the function to display sprint details
print_sprint_details(sprints)
Sprint1:
Tasks: ['Frontend Development', 'Github Pages Playground', 'Javascript Playground']
Duration: 2 weeks
Team Members: ['Mihir', 'Ansh', 'Derek', 'Pradyun']
Sprint2:
Tasks: ['Big Ideas 3.1', 'Big Ideas 3.2', 'Big Ideas 3.3', 'Big Ideas 3.4', 'Big Ideas 3.5', 'Big Ideas 3.6', 'Big Ideas 3.7', 'Big Ideas 3.8', 'Big Ideas 3.10']
Duration: 1 week
Team Members: ['Mihir', 'Ansh', 'Derek', 'Pradyun']
Popcorn Hack 3
Create a mix of list and dictionaries to represent a real world collection of data. I will do a car rental system.
# A list of dictionaries representing cars in a rental system
car_rental_system = [
{
"model": "Tesla Model 3",
"manufacturer": "Tesla",
"rental_rate": 150, # rate per day in USD
"available": True,
"renters": [
{"name": "John Doe", "rental_date": "2024-09-20", "return_date": "2024-09-25"},
{"name": "Jane Smith", "rental_date": "2024-10-01", "return_date": "2024-10-05"}
]
},
{
"model": "BMW X5",
"manufacturer": "BMW",
"rental_rate": 120,
"available": False,
"renters": [
{"name": "Alice Brown", "rental_date": "2024-09-15", "return_date": "2024-09-20"}
]
},
{
"model": "Toyota Corolla",
"manufacturer": "Toyota",
"rental_rate": 80,
"available": True,
"renters": []
}
]
# Function to display information about each car in the rental system
def print_car_rental_info(rental_system):
for car in rental_system:
print(f"Model: {car['model']}")
print(f"Manufacturer: {car['manufacturer']}")
print(f"Rental Rate: ${car['rental_rate']} per day")
print(f"Available: {'Yes' if car['available'] else 'No'}")
if car['renters']:
print("Renters:")
for renter in car['renters']:
print(f" - {renter['name']} (Rented from: {renter['rental_date']} to {renter['return_date']})")
else:
print("No renters yet.")
print("\n")
# Call the function to display the car rental system information
print_car_rental_info(car_rental_system)
Model: Tesla Model 3
Manufacturer: Tesla
Rental Rate: $150 per day
Available: Yes
Renters:
- John Doe (Rented from: 2024-09-20 to 2024-09-25)
- Jane Smith (Rented from: 2024-10-01 to 2024-10-05)
Model: BMW X5
Manufacturer: BMW
Rental Rate: $120 per day
Available: No
Renters:
- Alice Brown (Rented from: 2024-09-15 to 2024-09-20)
Model: Toyota Corolla
Manufacturer: Toyota
Rental Rate: $80 per day
Available: Yes
No renters yet.