Popcorn Hack 1

Code Runner Challenge

Popcorn Hack 1 - Check SFI Part Fields

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Check SFI Part Fields

part = {
    "product_name": "Replacement Flywheels and Clutch Assemblies",
    "category": "Auto Racing",
    "spec_number": "1.2",
    "effective_date": "Nov. 9, 2001"
}

valid_categories = ["Auto Racing", "Drag Racing"]

has_product_name = part["product_name"] != ""
has_valid_category = part["category"] in valid_categories
has_spec_number = part["spec_number"] != ""
has_effective_date = part["effective_date"] != ""

print("Product name:", has_product_name)
print("Racing category:", has_valid_category)
print("Spec number:", has_spec_number)
print("Effective date:", has_effective_date)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 2

Code Runner Challenge

Popcorn Hack 1 - Check SFI Part Fields

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Check SFI Part Fields

part = {
    "product_name": "Replacement Flywheels and Clutch Assemblies",
    "category": "Auto Racing",
    "spec_number": "1.1",
    "effective_date": "Nov. 9, 2001"
}

valid_categories = ["Auto Racing", "Drag Racing"]
existing_spec_numbers = ["1.1", "2.1"]

all_fields_valid = (
    part["product_name"] != ""
    and part["category"] in valid_categories
    and part["spec_number"] != ""
    and part["effective_date"] != ""
)
spec_is_new = part["spec_number"] not in existing_spec_numbers
print("Create database record:", all_fields_valid and spec_is_new)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Popcorn Hack 3

Code Runner Challenge

Popcorn Hack 3 - SFI Search Filter

View IPYNB Source
# CODE_RUNNER: Popcorn Hack 3 - SFI Search Filter

query = "1.2"

records = [
    {
        "product_name": "Replacement Flywheels and Clutch Assemblies",
        "category": "Auto Racing",
        "spec_number": "1.1"
    },
    {
        "product_name": "Multiple Disc Clutch Assemblies",
        "category": "Drag Racing",
        "spec_number": "1.2"
    },
    {
        "product_name": "Racing Flywheel Record",
        "category": "Auto Racing",
        "spec_number": "2.1"
    }
]

valid_categories = ["Auto Racing", "Drag Racing"]

matches = [
    record for record in records
    if record["category"] in valid_categories
    and (query == record["product_name"] or query == record["spec_number"])
]

print(matches)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

MCQ Check

  1. A
  2. C
  3. A
  4. B

Homework

Code Runner Challenge

Homework Hack - SFI Backend Validator

View IPYNB Source
# Homework Hack - SFI Backend Validator
# CODE_RUNNER: Homework Hack - SFI Backend Validator

existing_spec_numbers = ["1.1", "2.1"]
valid_categories = ["Auto Racing", "Drag Racing"]

test_records = [
    {
        "product_name": "Multiple Disc Clutch Assemblies",
        "category": "Auto Racing",
        "spec_number": "1.2",
        "effective_date": "Feb. 9, 2006"
    },
    {
        "product_name": "Replacement Flywheels",
        "category": "Street Car",
        "spec_number": "3.1",
        "effective_date": "Jan. 1, 2026"
    },
    {
        "product_name": "Existing Flywheel Record",
        "category": "Drag Racing",
        "spec_number": "1.1",
        "effective_date": "Jan. 1, 2026"
    }
]

def is_valid_candidate(record):
    has_required_fields = (
        record["product_name"] != ""
        and record["category"] in valid_categories
        and record["spec_number"] != ""
        and record["effective_date"] != ""
    )
    has_new_spec_number = record["spec_number"] not in existing_spec_numbers
    return has_required_fields and has_new_spec_number

for record in test_records:
    result = "ACCEPTED" if is_valid_candidate(record) else "REJECTED"
    print(record["product_name"], "-", result)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...