KNOWLEDGE CHECK

POPCORN HACK 1

Code Runner Challenge

POPCORN HACK 1

View IPYNB Source
# CODE_RUNNER: POPCORN HACK 1

def report_status(location, status):
    # TODO: Print a status update using both parameters
    print(f"Status update from {location}: {status}")


# TODO: Call report_status() two times
# TODO: Use a different location or status for each call
report_status("Poway", "Medical team dispatched")
report_status("San Diego", "Power restored")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

POPCORN HACK 2

Code Runner Challenge

POPCORN HACK 2

View IPYNB Source
# CODE_RUNNER: POPCORN HACK 2

# Helper Procedure
def is_priority(incident_type):
    # TODO: Return True when the incident is a "Medical Emergency"
    return incident_type == "Medical Emergency"


# Outer Procedure
def process_report(location, incident_type):
    # TODO: Call is_priority() using incident_type
    # TODO: Store the returned value in a variable
    priority = is_priority(incident_type)

    # TODO: Use an if/else statement
    # TODO: Print a priority message if priority is True
    # TODO: Otherwise, print a standard report message
    if priority:
        print(f"PRIORITY: {incident_type} reported in {location}")
    else:
        print(f"STANDARD REPORT: {incident_type} reported in {location}")


# TODO: Call process_report() two times
# TODO: Test it with different incident types
process_report("Poway", "Medical Emergency")
process_report("Poway", "Power Outage")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

HOMEWORK HACK

Code Runner Challenge

HOMEWORK HACK

View IPYNB Source
# CODE_RUNNER: HOMEWORK HACK

def check_priority(incident_type):
    # TODO: Return True when the incident requires priority handling
    priority_incidents = ["Medical Emergency", "Fire", "Gas Leak"]
    return incident_type in priority_incidents


def dispatch_response(location, incident_type):
    # TODO: Call check_priority()
    # TODO: Store the returned value in a variable
    needs_priority = check_priority(incident_type)

    # TODO: Use an if/else statement to print the appropriate response
    if needs_priority:
        print(f"Dispatch priority response to {location} for: {incident_type}")
    else:
        print(f"Dispatch standard response to {location} for: {incident_type}")


# TODO: Call dispatch_response() at least three times
dispatch_response("Poway", "Medical Emergency")
dispatch_response("San Diego", "Road Closure")
dispatch_response("Escondido", "Fire")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...