# Popcorn Hack 1
num_set = {1, 2, 3, 4, 5}
print("Initial Set: ", num_set)
num_set.add(6)
print("Set after adding 6: ", num_set)
num_set.remove(2)
print("Set after removing 2: ", num_set)
union_set = num_set.union({7, 8, 9})
print("Union of Set with {7, 8, 9}: ", union_set)
num_set.clear()
print("Set after clearing: ", num_set)
#Bonus
bonus_set = {1,2,2,3,3,4}
print("Bonus Set: ", bonus_set)
print("Length of Bonus Set: ", len(bonus_set))
Initial Set: {1, 2, 3, 4, 5}
Set after adding 6: {1, 2, 3, 4, 5, 6}
Set after removing 2: {1, 3, 4, 5, 6}
Union of Set with {7, 8, 9}: {1, 3, 4, 5, 6, 7, 8, 9}
Set after clearing: set()
Bonus Set: {1, 2, 3, 4}
Length of Bonus Set: 4
# Popcorn Hack 2
string = "Learning Python is not fun"
print("Initial String: ", string)
print("Length of String: ", len(string))
python_substring = string[9:15] #Slicing Pything from the string
print("Python Substring: ", python_substring)
print("uppercase string: ", string.upper())
new_string = string.replace("fun", "good")
print("String after replacing 'fun' with 'good': ", new_string)
#Bonus
print("reversed string: ", string[::-1])
Initial String: Learning Python is not fun
Length of String: 26
Python Substring: Python
uppercase string: LEARNING PYTHON IS NOT FUN
String after replacing 'fun' with 'good': Learning Python is not good
reversed string: nuf ton si nohtyP gninraeL
# Popcorn Hack 3
numbers = [3, 5, 7, 9, 11]
print("Original list:", numbers)
print("Third element:", numbers[2])
numbers[1] = 6
print("List after modifying the second element:", numbers)
numbers.append(13)
print("List after appending 13:", numbers)
numbers.remove(9)
print("List after removing 9:", numbers)
# Bonus
numbers.sort(reverse=True)
print("List sorted in descending order:", numbers)
Original list: [3, 5, 7, 9, 11]
Third element: 7
List after modifying the second element: [3, 6, 7, 9, 11]
List after appending 13: [3, 6, 7, 9, 11, 13]
List after removing 9: [3, 6, 7, 11, 13]
List sorted in descending order: [13, 11, 7, 6, 3]
# Popcorn Hack 4
personal_info = {
"name": "Rayhaan",
"email": "totallyreal@email.com",
"phone number": "123-456-7899"
}
print("Personal Info Dictionary:", personal_info)
print("My Name is:", personal_info["name"])
print("Length of the dictionary:", len(personal_info))
print("Type of the dictionary:", type(personal_info))
# Bonus
new_info = {
"name": "Bob",
"email": "hellooo@gmail.com",
"phone number": "111-111-1111"
}
print("New Info Dictionary:", new_info)
print("New Name is:", new_info["name"])
print("New Email is:", new_info["email"])
print("New Phone Number is:", new_info["phone number"])
print("Length of the new dictionary:", len(new_info))
print("Type of the new dictionary:", type(new_info))
Personal Info Dictionary: {'name': 'Rayhaan', 'email': 'totallyreal@email.com', 'phone number': '123-456-7899'}
My Name is: Rayhaan
Length of the dictionary: 3
Type of the dictionary: <class 'dict'>
New Info Dictionary: {'name': 'Bob', 'email': 'hellooo@gmail.com', 'phone number': '111-111-1111'}
New Name is: Bob
New Email is: hellooo@gmail.com
New Phone Number is: 111-111-1111
Length of the new dictionary: 3
Type of the new dictionary: <class 'dict'>
# Homework Hack Python
#Part 1
personal_info = { "full_name": "Rayhaan Sheeraj", "years": 15, "location": "San Diego", "favorite_food": "pizza" }
print("Personal Info:", personal_info)
#Part 2
favorite_activities = ["Coding", "Sleeping", "Gaming"]
print("Activities:", favorite_activities)
#Part 3
personal_info["activities"] = favorite_activities
print("Personal Info with Activities:", personal_info)
#Part 4
activity_availability = { "Coding": True, "Sleeping": True, "Gaming": False }
print("Which activities are availabe today:", activity_availability)
#Part 5
total_activities = len(favorite_activities)
print(f"I have {total_activities} activities.")
#Part 6
most_favorite_activities = ("Gaming", "Sleeping")
print("My Favorite Activities:", most_favorite_activities)
#Part 7
skills = {"Coding", "Gaming", "Playing Brawl Stars"}
print("Skills:", skills)
#Part 8
new_skill = None
print(new_skill)
#Part 9
activity_cost = 5.0
skill_cost = 10.0
total_cost = (total_activities * activity_cost) + (len(skills) * skill_cost)
print(f"The total cost to pursue all activities and develop all skills is: ${total_cost:.2f}")
Personal Info: {'full_name': 'Rayhaan Sheeraj', 'years': 15, 'location': 'San Diego', 'favorite_food': 'pizza'}
Activities: ['Coding', 'Sleeping', 'Gaming']
Personal Info with Activities: {'full_name': 'Rayhaan Sheeraj', 'years': 15, 'location': 'San Diego', 'favorite_food': 'pizza', 'activities': ['Coding', 'Sleeping', 'Gaming']}
Which activities are availabe today: {'Coding': True, 'Sleeping': True, 'Gaming': False}
I have 3 activities.
My Favorite Activities: ('Gaming', 'Sleeping')
Skills: {'Playing Brawl Stars', 'Gaming', 'Coding'}
None
The total cost to pursue all activities and develop all skills is: $45.00
// Javascript Popcorn Hack 1
let Set1 = new Set([1, 2, 3, 4, 5]);
console.log("Set1: ", Set1);
let Set2 = new Set([4, 5, 6, 7, 8]);
console.log("Set2: ", Set2);
Set1.add(21);
console.log("Set1 after adding 21: ", Set1);
Set1.delete(1);
console.log("Set1 after deleting 1: ", Set1);
let unionSet = new Set([...Set1, ...Set2]);
console.log("Union of Set1 and Set2: ", unionSet);
// Javascript Popcorn Hack 2
let application = {
name: "Joe",
age: 2,
experiences: ["Brawl Stars Esports", "Clash Royale Esports", "Clash of Clans Esports"],
money: 10000000
};
console.log("Application: ", application);
console.log("Money: ", application.money);