3.2 Popcorn Hacks

Popcorn Hack 1

bestDictionaryEver = {"dodgers": 1, "padres": 2, "giants": 3}
print(bestDictionaryEver["padres"])
    
2
Popcorn Hack 2
firstNumber = int(input("Please Enter the First Number Here: "))
secondNumber = int(input("Please Enter the Second Number Here: "))
mathFunction = (input("Please Enter the function here: ")) 

if mathFunction == "+":
    print(firstNumber + secondNumber)
elif mathFunction == "-":
    print(firstNumber - secondNumber)
elif mathFunction == "*":
    print(firstNumber * secondNumber)
elif mathFunction == "/":
    print(firstNumber / secondNumber)
70
Popcorn Hack 3
def repeat_strings_in_list(strings, n): 
    result = [] 
    for string in strings:
        result.append(string * n) 
    return result

string_list = ["wassup", "bruh", "coding"]
print(repeat_strings_in_list(string_list, 5))
['wassupwassupwassupwassupwassup', 'bruhbruhbruhbruhbruh', 'codingcodingcodingcodingcoding']
Popcorn Hack 4
def sets_have_common_elements(set1, set2):
    for elem in set1:
        if elem in set2:
            return True
    return False
print(sets_have_common_elements({24, 212, 68}, {15, 212}))  
print(sets_have_common_elements({6, 57, 13}, {99, 24})) 
print(sets_have_common_elements({123, 49}, {51}))       
print(sets_have_common_elements({239031}, {239031}))             
True
False
False
True

3.2 Homework Hacks

Homework Hack 1
profile = {
    "name": "Zach",
    "age": 15,
    "hobbies": "sports, games",
    "classes": "CSP, math, physics",
}
print("Profile:", profile)
Profile: {'name': 'Zach', 'age': 15, 'hobbies': 'sports, games', 'classes': 'CSP, math, physics'}
Homework Hack 2
hobbies = ["Traveling", "Exploring", "Creating"]
print("Interests:", hobbies)
Interests: ['Traveling', 'Exploring', 'Creating']
Homework Hack 3
profile["hobbies"] = hobbies
print("Updated Profile:", profile)
Updated Profile: {'name': 'Zach', 'age': 15, 'hobbies': ['Traveling', 'Exploring', 'Creating'], 'classes': 'CSP, math, physics'}
Homework Hack 4
has_hobby = True 
print(f"Is {hobbies[2]} available today? {has_hobby}")
Is Creating available today? True
Homework Hack 5
total_hobbies = len(hobbies)
print(f"I have {total_hobbies} hobbies.")
I have 3 hobbies.
Homework Hack 6
favorite_hobbies = ("Gaming", "Sports", "Reading", "Baking")
print("Favorite Hobbies:", favorite_hobbies)
Favorite Hobbies: ('Gaming', 'Sports', 'Reading', 'Baking')
Homework Hack 7
skills = {"Driving", "Working", "Coding"}
print("Skills:", skills)
Skills: {'Coding', 'Driving', 'Working'}
Homework Hack 8
new_skill = True
print("New Skill: Writing", new_skill)
New Skill: Writing True
Homework Hack 9
total_cost = float(total_hobbies * 24 + len(skills) * 35)
print(f"Cost for my hobbies and skillsets: ${total_cost:.2f}")
Cost for my hobbies and skillsets: $177.00