Skip to the content.

3.2 Teamteach_ipynb_2_

Popcorn Hack 1:

my_set = {1, 2, 3, 4, 5}
print("Step 1 - Initial set:", my_set)

my_set.add(6)
print("Step 2 - After adding 6:", my_set)

my_set.remove(2)
print("Step 3 - After removing 2:", my_set)

union_set = my_set.union({7, 8, 9})
print("Step 4 - Union with {7, 8, 9}:", union_set)

my_set.clear()
print("Step 5 - After clearing the set:", my_set)

bonus_set = {1, 2, 2, 3, 3, 4}
print("Bonus - Set with duplicates:", bonus_set)
print("Bonus - Length of set:", len(bonus_set))

PopCorn Hack 2:

my_string = "Learning Python is not fun"
print("Step 1 - Initial string:", my_string)

string_length = len(my_string)
print("Step 2 - String length:", string_length)

sliced_string = my_string[9:15]
print("Step 3 - Sliced string (Python):", sliced_string)

uppercase_string = my_string.upper()
print("Step 4 - Uppercase string:", uppercase_string)

replaced_string = my_string.replace("fun", "good")
print("Step 5 - Replaced string:", replaced_string)

reversed_string = my_string[::-1]
print("Bonus - Reversed string:", reversed_string)

Popcorn Hack 3:

my_list = [3, 5, 7, 9, 11]
print("Step 1 - Initial list:", my_list)

third_element = my_list[2]
print("Step 2 - Third element:", third_element)

my_list[1] = 6
print("Step 3 - After modifying second element:", my_list)

my_list.append(13)
print("Step 4 - After appending 13:", my_list)

my_list.remove(9)
print("Step 5 - After removing 9:", my_list)

my_list.sort(reverse=True)
print("Bonus - Sorted list in descending order:", my_list)

Popcorn Hack 4:

personal_info = {
    "name": "John Doe",
    "email": "john.doe@example.com",
    "phone number": "123-456-7890"
}
print("Step 2 - Personal Info Dictionary:", personal_info)

print("Step 3 - My Name is:", personal_info["name"])

dictionary_length = len(personal_info)
print("Step 4 - Length of Dictionary:", dictionary_length)

dictionary_type = type(personal_info)
print("Step 5 - Type of Dictionary:", dictionary_type)

# Bonus
second_personal_info = {
    "name": "Jane Smith",
    "email": "jane.smith@example.com",
    "phone number": "098-765-4321"
}
print("Bonus - Second Personal Info Dictionary:", second_personal_info)

print("Bonus - First Name:", personal_info["name"], "Second Name:", second_personal_info["name"])
print("Bonus - First Email:", personal_info["email"], "Second Email:", second_personal_info["email"])
print("Bonus - First Phone Number:", personal_info["phone number"], "Second Phone Number:", second_personal_info["phone number"])

Homework Hack Python:

# Part 1: Create Personal Info (dict)
personal_info = {
    "full_name": "Hannah Li",
    "years": 17,
    "location": "San Diego",
    "favorite_food": "noodles"
}
print("Part 1 - Personal Info:", personal_info)

# Part 2: Create a List of Activities (list)
activities = ["reading", "basketball", "painting"]
print("Part 2 - Activities List:", activities)

# Part 3: Add Activities to Personal Info (dict and list)
personal_info["activities"] = activities
print("Part 3 - Updated Personal Info with Activities:", personal_info)

# Part 4: Check Availability of an Activity (bool)
activity_available = True  # assuming 'cycling' is available today
print(f"Part 4 - Is basketball available today? {activity_available}")

# Part 5: Total Number of Activities (int)
total_activities = len(activities)
print(f"Part 5 - I have {total_activities} activities.")

# Part 6: Favorite Activities (tuple)
favorite_activities = ("reading", "painting")
print("Part 6 - Favorite Activities:", favorite_activities)

# Part 7: Add a New Set of Skills (set)
skills = {"problem-solving", "public speaking", "time management"}
print("Part 7 - Skills Set:", skills)

# Part 8: Consider a New Skill (NoneType)
new_skill = None
print("Part 8 - New Skill:", new_skill)

# Part 9: Calculate Total Hobby and Skill Cost (float)
activity_cost = 5.0  # each activity costs $5
skill_cost = 10.0  # each skill costs $10
total_cost = total_activities * activity_cost + len(skills) * skill_cost
print(f"Part 9 - Total Cost: ${total_cost}")

Part 1 - Personal Info: {'full_name': 'Hannah Li', 'years': 17, 'location': 'San Diego', 'favorite_food': 'noodles'}
Part 2 - Activities List: ['reading', 'basketball', 'painting']
Part 3 - Updated Personal Info with Activities: {'full_name': 'Hannah Li', 'years': 17, 'location': 'San Diego', 'favorite_food': 'noodles', 'activities': ['reading', 'basketball', 'painting']}
Part 4 - Is basketball available today? True
Part 5 - I have 3 activities.
Part 6 - Favorite Activities: ('reading', 'painting')
Part 7 - Skills Set: {'public speaking', 'time management', 'problem-solving'}
Part 8 - New Skill: None
Part 9 - Total Cost: $45.0

Javascript Popcorn Hacks

Popcorn Hack 1:

%%js 
let Set1 = new Set([1, 2, 3]);
let Set2 = new Set([4, 5, 6]);

console.log("Set1:", Set1);
console.log("Set2:", Set2);

Set1.add(7);
Set1.delete(1);

console.log("Set1 after adding 7 and removing 1:", Set1);

let unionSet = new Set([...Set1, ...Set2]);
console.log("Union of Set1 and Set2:", unionSet);

Popcorn Hack 2:

%%js 
let application = {
    name: "John Snow",
    age: 20,
    experiences: ["internship", "volunteering", "teaching"],
    money: 5000
};

console.log(application);
console.log(application.money);

Homework Hack Javascript:

%%js 
let applicantName = prompt("What is your name?");
let applicantAge = prompt("What is your age?");
let applicantExperiences = prompt("List your experiences (separated by commas)");

let application = {
    name: applicantName,
    age: parseInt(applicantAge),
    experiences: applicantExperiences.split(",")
};

console.log("Applicant's Info:", application);