Popcorn Hack 1 Python: Popcorn Hack!
# Step 1: Create a Set
my_set = {1, 2, 3, 4, 5}
print("Initial Set:", my_set)
# Step 2: Add an Element
my_set.add(6)
print("After Adding 6:", my_set)
# Step 3: Remove an Element
my_set.discard(2) # Using discard to avoid KeyError if 2 is not in the set
print("After Removing 2:", my_set)
# Step 4: Union of Sets
another_set = {7, 8, 9}
my_set = my_set.union(another_set)
print("After Union with {7, 8, 9}:", my_set)
# Step 5: Clear the Set
my_set.clear()
print("After Clearing the Set:", my_set)
# Bonus: Create a set with duplicates
duplicate_set = {1, 2, 2, 3, 3, 4}
print("Set with Duplicates:", duplicate_set)
print("Length of Set with Duplicates:", len(duplicate_set))
Initial Set: {1, 2, 3, 4, 5}
After Adding 6: {1, 2, 3, 4, 5, 6}
After Removing 2: {1, 3, 4, 5, 6}
After Union with {7, 8, 9}: {1, 3, 4, 5, 6, 7, 8, 9}
After Clearing the Set: set()
Set with Duplicates: {1, 2, 3, 4}
Length of Set with Duplicates: 4
Popcorn Hack 2 Python
# Step 1: Create a String
my_string = "Learning Python is not fun"
print("Original String:", my_string)
# Step 2: String Length
string_length = len(my_string)
print("Length of the String:", string_length)
# Step 3: String Slicing
extracted_word = my_string[9:15] # Extracting "Python"
print("Extracted Word:", extracted_word)
# Step 4: String Uppercase
uppercase_string = my_string.upper()
print("Uppercase String:", uppercase_string)
# Step 5: String Replace
replaced_string = my_string.replace("fun", "good")
print("Replaced String:", replaced_string)
# Bonus: Reverse the String using slicing
reversed_string = my_string[::-1]
print("Reversed String:", reversed_string)
Original String: Learning Python is not fun
Length of the String: 26
Extracted Word: Python
Uppercase String: LEARNING PYTHON IS NOT FUN
Replaced String: Learning Python is not good
Reversed String: nuf ton si nohtyP gninraeL
Popcorn Hack 3 Python
# Step 1: Create a List
numbers = [3, 5, 7, 9, 11]
print("Original List:", numbers)
# Step 2: Access an Element
third_element = numbers[2] # Accessing the third element (index 2)
print("Third Element:", third_element)
# Step 3: Modify an Element
numbers[1] = 6 # Changing the second element (index 1) to 6
print("Modified List (Changed 5 to 6):", numbers)
# Step 4: Add an Element
numbers.append(13) # Appending 13 to the list
print("List After Appending 13:", numbers)
# Step 5: Remove an Element
numbers.remove(9) # Removing the element 9 from the list
print("List After Removing 9:", numbers)
# Bonus: Sort the list in descending order
numbers.sort(reverse=True)
print("Sorted List in Descending Order:", numbers)
Original List: [3, 5, 7, 9, 11]
Third Element: 7
Modified List (Changed 5 to 6): [3, 6, 7, 9, 11]
List After Appending 13: [3, 6, 7, 9, 11, 13]
List After Removing 9: [3, 6, 7, 11, 13]
Sorted List in Descending Order: [13, 11, 7, 6, 3]
Popcorn Hack 4 Python
# Step 1: Create a Dictionary
personal_info = {
"name": "kushi gade",
"email": "kushi.gade@example.com",
"phone number": "123-456-7890"
}
# Step 2: Print out the Dictionary
print("Personal Info Dictionary:", personal_info)
# Step 3: Print out the name from your dictionary
print("My Name is:", personal_info["name"])
# Step 4: Print the Length
print("Length of the Dictionary:", len(personal_info))
# Step 5: Print the Type
print("Type of the Dictionary:", type(personal_info))
# Bonus: Add another dictionary
additional_info = {
"name": "Maraym Abdul-Azkz",
"email": "Maryam.Abdul.Azkzh@example.com",
"phone number": "098-765-4321"
}
# Print values from the additional dictionary
print("\nAdditional Info Dictionary:", additional_info)
print("My Name is:", additional_info["name"])
Personal Info Dictionary: {'name': 'kushi gade', 'email': 'kushi.gade@example.com', 'phone number': '123-456-7890'}
My Name is: kushi gade
Length of the Dictionary: 3
Type of the Dictionary: <class 'dict'>
Additional Info Dictionary: {'name': 'Maraym Abdul-Azkz', 'email': 'Maryam.Abdul.Azkzh@example.com', 'phone number': '098-765-4321'}
My Name is: Maraym Abdul-Azkz
Homework Hacks Python Part 1
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade", # String
"years": 30, # Integer
"location": "New York", # String
"favorite_food": "Pizza" # String
}
# Print the personal_info dictionary
print(personal_info)
{'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza'}
Homework hacks Python Part 2
# Part 2: Create a List of Activities (list)
activities = ["Reading", "Hiking", "Cooking"]
# Print the activities list
print(activities)
['Reading', 'Hiking', 'Cooking']
Homework hacks Python part 3
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade",
"years": 30,
"location": "New York",
"favorite_food": "Pizza"
}
# Part 2: Create a List of Activities (list)
activities = ["Hiking", "Reading", "Cooking"]
print("Activities List:", activities)
# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
# Print the updated personal_info dictionary
print("Updated Personal Info:", personal_info)
Activities List: ['Hiking', 'Reading', 'Cooking']
Updated Personal Info: {'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza', 'activities': ['Hiking', 'Reading', 'Cooking']}
Homework hacks Python part 4
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade",
"years": 30,
"location": "New York",
"favorite_food": "Pizza"
}
# Part 2: Create a List of Activities (list)
activities = ["Hiking", "Reading", "Cooking"]
print("Activities List:", activities)
# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
print("Updated Personal Info:", personal_info)
# Part 4: Check Availability of an Activity (bool)
activity_to_check = "Hiking"
activity_available = True # Set to True or False based on availability
# Print message about activity availability
print(f"Is {activity_to_check} available today? {activity_available}")
Activities List: ['Hiking', 'Reading', 'Cooking']
Updated Personal Info: {'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza', 'activities': ['Hiking', 'Reading', 'Cooking']}
Is Hiking available today? True
Homework hacks Python part 5
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade",
"years": 30,
"location": "New York",
"favorite_food": "Pizza"
}
# Part 2: Create a List of Activities (list)
activities = ["Hiking", "Reading", "Cooking"]
print("Activities List:", activities)
# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
print("Updated Personal Info:", personal_info)
# Part 4: Check Availability of an Activity (bool)
activity_to_check = "Hiking"
activity_available = True # Set to True or False based on availability
# Print message about activity availability
print(f"Is {activity_to_check} available today? {activity_available}")
# Part 5: Total Number of Activities (int)
total_activities = len(activities) # Count the number of activities
# Print message about total activities
print(f"I have {total_activities} activities.")
Activities List: ['Hiking', 'Reading', 'Cooking']
Updated Personal Info: {'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza', 'activities': ['Hiking', 'Reading', 'Cooking']}
Is Hiking available today? True
I have 3 activities.
Homework hacks Python part 6
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade",
"years": 30,
"location": "New York",
"favorite_food": "Pizza"
}
# Part 2: Create a List of Activities (list)
activities = ["Hiking", "Reading", "Cooking"]
print("Activities List:", activities)
# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
print("Updated Personal Info:", personal_info)
# Part 4: Check Availability of an Activity (bool)
activity_to_check = "Hiking"
activity_available = True # Set to True or False based on availability
# Print message about activity availability
print(f"Is {activity_to_check} available today? {activity_available}")
# Part 5: Total Number of Activities (int)
total_activities = len(activities) # Count the number of activities
# Print message about total activities
print(f"I have {total_activities} activities.")
# Part 6: Favorite Activities (tuple)
favorite_activities = ("Hiking", "Reading")
print("Favorite Activities:", favorite_activities)
Activities List: ['Hiking', 'Reading', 'Cooking']
Updated Personal Info: {'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza', 'activities': ['Hiking', 'Reading', 'Cooking']}
Is Hiking available today? True
I have 3 activities.
Favorite Activities: ('Hiking', 'Reading')
Homework hacks Python part 7
# Part 1: Create Personal Info (dict)
personal_info = {
"full_name": "Kushi Gade",
"years": 30,
"location": "New York",
"favorite_food": "Pizza"
}
# Part 2: Create a List of Activities (list)
activities = ["Hiking", "Reading", "Cooking"]
print("Activities List:", activities)
# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
print("Updated Personal Info:", personal_info)
# Part 4: Check Availability of an Activity (bool)
activity_to_check = "Hiking"
activity_available = True # Set to True or False based on availability
# Print message about activity availability
print(f"Is {activity_to_check} available today? {activity_available}")
# Part 5: Total Number of Activities (int)
total_activities = len(activities) # Count the number of activities
# Print message about total activities
print(f"I have {total_activities} activities.")
# Part 6: Favorite Activities (tuple)
favorite_activities = ("Hiking", "Reading")
print("Favorite Activities:", favorite_activities)
# Part 7: Add a New Set of Skills (set)
skills = {"Python", "Communication", "Problem Solving"} # Create a set of unique skills
print("Skills Set:", skills) # Print the set of skills
Activities List: ['Hiking', 'Reading', 'Cooking']
Updated Personal Info: {'full_name': 'Kushi Gade', 'years': 30, 'location': 'New York', 'favorite_food': 'Pizza', 'activities': ['Hiking', 'Reading', 'Cooking']}
Is Hiking available today? True
I have 3 activities.
Favorite Activities: ('Hiking', 'Reading')
Skills Set: {'Problem Solving', 'Python', 'Communication'}
Homework hacks Python part 8
# Part 7: Add a New Set of Skills (set)
skills = {"coding", "painting", "cooking"} # Added random skills
print(skills)
{'painting', 'coding', 'cooking'}
Homework hacks Python part 9
activities = ["hiking", "swimming", "reading"]
skills = {"coding", "painting", "cooking", "photography"}
# Cost definitions
activity_cost = 5.0 # Cost per activity
skill_cost = 10.0 # Cost per skill
# Calculate total cost
total_cost = (len(activities) * activity_cost) + (len(skills) * skill_cost)
# Print total cost
print(f"The total cost to develop all activities and skills is: ${total_cost:.2f}")
The total cost to develop all activities and skills is: $55.00
Javascript Popcorn hack 1
%%js
// Step 1: Create Set1 with 3 random numbers
let Set1 = new Set([12, 25, 38]);
console.log("Set1:", Set1); // Log Set1
// Step 2: Create Set2 with different 3 random numbers
let Set2 = new Set([47, 52, 64]);
console.log("Set2:", Set2); // Log Set2
// Step 3: Add a random number to Set1
Set1.add(99);
console.log("Set1 after adding 99:", Set1); // Log Set1 after adding
// Step 4: Remove the 1st number from Set1 (in this case, 12)
Set1.delete(12);
console.log("Set1 after removing 12:", Set1); // Log Set1 after removing
// Step 5: Log the union of both Set1 and Set2
let unionSet = new Set([...Set1, ...Set2]);
console.log("Union of Set1 and Set2:", unionSet); // Log the union of both sets
<IPython.core.display.Javascript object>
Javascript Popcorn hack 2
%%js
// Step 1: Create a Dictionary called "application"
let application = {
name: "Kushi",
age: 30,
experiences: ["software developer", "data analyst", "project manager"],
money: 1500.50
};
// Step 2: Log the dictionary to make sure it works
console.log("Application Dictionary:", application); // Log the entire dictionary
// Step 3: Log only the dictionary's money
console.log("Money:", application.money); // Log only the money
<IPython.core.display.Javascript object>
Javascript Homework Hack
%%js
// Step 1: Create an empty dictionary for the applicant
let applicant = {};
// Step 2: Predefined inputs for the applicant
applicant.name = "Kushi Gade";
applicant.age = "30";
applicant.experiences = ["Web Development", "Project Management", "Graphic Design"]; // Example experiences
// Step 3: Log the user's input
console.log("Applicant Information:");
console.log("Name:", applicant.name);
console.log("Age:", applicant.age);
console.log("Experiences:", applicant.experiences);
<IPython.core.display.Javascript object>