Code Runner Challenge

3.6 Homework

View IPYNB Source
# CODE_RUNNER: 3.6 Homework

test_cases = [
    ("URGENT: send gift cards now to unlock your account", 500, False),  # every signal
    ("Can you send a gift card?", 25, True),                            # one signal
    ("Let's meet for coffee tomorrow", 0, True),                        # clean message
]

for message, amount_requested, known_contact in test_cases:
    risk_score = 0

    # Each signal is independent: a message can trip several, so no else is needed.
    # A signal that is not there should add 0, not run another branch.
    if "gift card" in message.lower():
        risk_score = risk_score + 4
    if amount_requested > 100:
        risk_score = risk_score + 3
    if not known_contact:
        risk_score = risk_score + 2

    # 3 thresholds -> 4 outcomes -> 4 answers
    #   9      all three signals
    #   6-8    gift cards + unknown contact (6)
    #   3-5    amount over 100 only (3)
    #   0-2    clean message, small amount, known contact (0)
    if risk_score >= 9:
        advice = "Very high risk: do not reply, report it, and call the family."
    elif risk_score >= 6:
        advice = "High risk: do not reply, and ask someone you trust first."
    elif risk_score >= 3:
        advice = "Some risk: slow down and check with the sender another way."
    else:
        advice = "Low risk: still look before you click."

    print("Message:", message)
    print("Risk score:", risk_score, "|", advice)
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...