Skip to the content.

3.1/3.4 Hacks

Popcorn and Homework hacks for 3.1/3.4

#Popcorn Hack for 3.1
name = input("What is your name?: ")
age = input("What is your age?: ")
favorite_brawler = input("What is your favorite Brawl Stars brawler?: ")
favorite_color = input("What is your favorite color?: ")
hobby = input("What is your favorite hobby?: ")
location = input("Where are you located?: ")

profile_list = [name, age, favorite_brawler, favorite_color, hobby, location]

profile_dict = {
    "Name": name,
    "Age": age,
    "Favorite Brawler": favorite_brawler,
    "Favorite Color": favorite_color,
    "Hobby": hobby,
    "Location": location
}

print("\nProfile List:")
print(profile_list)
print("\nProfile Dictionary:")
print(profile_dict)

print("\nProfile Summary:")
print("Hi, my name is " + name + ", I'm " + age + " years old, my favorite brawler is " + favorite_brawler +
      ", my favorite color is " + favorite_color + ", I enjoy " + hobby + ", and I'm located in " + location + ".")

What is your name?:  Shawn Ray
What is your age?:  15
What is your favorite Brawl Stars brawler?:  Jessie
What is your favorite color?:  Blue
What is your favorite hobby?:  Running
Where are you located?:  My Bed



Profile List:
['Shawn Ray', '15', 'Jessie', 'Blue', 'Running', 'My Bed']

Profile Dictionary:
{'Name': 'Shawn Ray', 'Age': '15', 'Favorite Brawler': 'Jessie', 'Favorite Color': 'Blue', 'Hobby': 'Running', 'Location': 'My Bed'}

Profile Summary:
Hi, my name is Shawn Ray, I'm 15 years old, my favorite brawler is Jessie, my favorite color is Blue, I enjoy Running, and I'm located in My Bed.
#Homework Hack for 3.1 (Will show up in console as well as in the form of an alert)
%%javascript

let firstName = "Shawn";
let lastName = "Ray";
let age = 15;
let email = "shawnyray116@gmail.com";
let favoriteSport = "Soccer";
let city = "San Diego";

let uniqueID = (firstName.substring(0, 3) + lastName.substring(0, 3) + age).toUpperCase();

let personalInfo = {
    fullName: `${firstName} ${lastName}`,
    age: age,
    email: email,
    favoriteSport: favoriteSport,
    city: city,
    uniqueID: uniqueID
};

function displayInfoConsole(info) {
    console.log("=== Personal Information ===");
    console.log(`- Full Name: ${info.fullName}`);
    console.log(`- Age: ${info.age}`);
    console.log(`- Email: ${info.email}`);
    console.log(`- Favorite Sport: ${info.favoriteSport}`);
    console.log(`- City: ${info.city}`);
    console.log(`- Unique ID: ${info.uniqueID}`);
}

alert(`=== Personal Information ===\n- Full Name: ${firstName} ${lastName}\n- Age: ${age}\n- Email: ${email}\n- Favorite Sport: ${favoriteSport}\n- City: ${city}\n- Unique ID: ${uniqueID}`);

<IPython.core.display.Javascript object>
#Popcorn hack for 3.4
#Example of bad password input
import re

def simple_password_validator(password):
    if len(password) < 8:
        return "Password too short. Must be at least 8 characters."

    if password.islower() or password.isupper():
        return "Password must contain both uppercase and lowercase letters."

    if not re.search(r'\d', password):
        return "Password must contain at least one number."

    if not re.search(r'[!@#$%^&*()_+]', password):
        return "Password must contain at least one special character (e.g. !, @, #, etc.)."

    common_passwords = ["password", "123456", "shawnrayisabaddie", "qwerty"]
    if password.lower() in common_passwords:
        return "Password is too common. Choose something less predictable."

    customized_password = password.replace("123", "abc")

    return f"Password is valid! Here’s a more secure version if needed: {customized_password}"

print(simple_password_validator("shawnrayisabaddie")) 
Password must contain both uppercase and lowercase letters.
#Example of good password input
import re

def simple_password_validator(password):
    if len(password) < 8:
        return "Password too short. Must be at least 8 characters."

    if password.islower() or password.isupper():
        return "Password must contain both uppercase and lowercase letters."

    if not re.search(r'\d', password):
        return "Password must contain at least one number."

    if not re.search(r'[!@#$%^&*()_+]', password):
        return "Password must contain at least one special character (e.g. !, @, #, etc.)."

    common_passwords = ["password", "123456", "shawnrayisabaddie", "qwerty"]
    if password.lower() in common_passwords:
        return "Password is too common. Choose something less predictable."

    customized_password = password.replace("123", "abc")

    return f"Password is valid! Here’s a more secure version if needed: {customized_password}"

print(simple_password_validator("HelloWorld123!")) 
Password is valid! Here’s a more secure version if needed: HelloWorldabc!
#Homework hack for 3.4
%%javascript


function simplePasswordValidator(password) {
    if (password.length < 8) {
        return "Password too short. Must be at least 8 characters.";
    }
    if (password === password.toLowerCase() || password === password.toUpperCase()) {
        return "Password must contain both uppercase and lowercase letters.";
    }
    if (!/\d/.test(password)) {
        return "Password must contain at least one number.";
    }
    if (!/[!@#$%^&*()_+]/.test(password)) {
        return "Password must contain at least one special character (e.g. !, @, #, etc.).";
    }
    const commonPasswords = ["password", "123456", "letmein", "qwerty"];
    if (commonPasswords.includes(password.toLowerCase())) {
        return "Password is too common. Choose something less predictable.";
    }
    return "Password is valid!";
}

console.log(simplePasswordValidator("HelloWorld123!"));


<IPython.core.display.Javascript object>

Done :)