Code Runner Challenge

popcorn 1

View IPYNB Source
# CODE_RUNNER: popcorn 1

amount_requested = 0

# 1 condition -> 2 outcomes -> 2 answers
if amount_requested > 100:
    print("This message is asking for a large amount of money.")
else:
    print("This message is asking for a small amount or no money.")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Code Runner Challenge

popcorn 2

View IPYNB Source
# CODE_RUNNER: popcorn 2

risk_score = 9

if risk_score >= 9:
    print("Do not reply. This is almost certainly a scam.")
elif risk_score >= 6:
    print("This looks risky. Check with someone you trust before replying.")
elif risk_score >= 3:
    print("Be a little careful, but this is probably fine.")
else:
    print("Nothing suspicious in this message.")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...

Code Runner Challenge

3.6 Homework - score a message, then advise on it

View IPYNB Source
# CODE_RUNNER: 3.6 Homework - score a message, then advise on it

message = "URGENT: send gift cards now to unlock your account"
amount_requested = 500
known_contact = False

risk_score = 0

# TODO 1: add to risk_score using conditionals, one signal at a time
# Note: These do not need an else because independent risk signals can accumulate. 
# A message can trigger multiple flags simultaneously (e.g., gift cards + high amount + unknown contact). 
# An else statement would only handle the opposite of a single signal and could prematurely overwrite the score.

# Signal 1: Mentions gift cards (+4)
if "gift card" in message.lower() or "gift cards" in message.lower():
    risk_score += 4

# Signal 2: Amount requested is over 100 (+3)
if amount_requested > 100:
    risk_score += 3

# Signal 3: Sender is not a known contact (+2)
if not known_contact:
    risk_score += 2


# TODO 3: Count comment with real numbers
# 3 thresholds -> 4 outcomes -> 4 answers

# TODO 2: report on the final score with an if / elif / else chain
if risk_score >= 7:
    print(f"Risk Score {risk_score}: High risk! Do not reply, this is likely a scam.")
elif risk_score >= 4:
    print(f"Risk Score {risk_score}: Moderate risk. This looks suspicious. Check with someone you trust.")
elif risk_score >= 2:
    print(f"Risk Score {risk_score}: Low risk. Be a little careful, but this is probably fine.")
else:
    print(f"Risk Score {risk_score}: Nothing suspicious in this message.")
Lines: 1 Characters: 0
Output
Click "Run" in code control panel to see output ...