Code Runner Challenge

3.05 Homework

View IPYNB Source
# CODE_RUNNER: 3.05 Homework

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"},
]

for record in test_records:
    has_product = record["product_name"] != ""
    has_category = record["category"] in valid_categories
    has_spec = record["spec_number"] != ""
    has_date = record["effective_date"] != ""
    is_new_spec = record["spec_number"] not in existing_spec_numbers

    accepted = has_product and has_category and has_spec and has_date and is_new_spec

    print("Record:", record["product_name"])

    if accepted:
        print("Decision: ACCEPTED")
    else:
        print("Decision: REJECTED - at least one requirement is False")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...