3.4 Strings HW
Popcorn Hack 1: Extract the Hidden Message
Only indexing and slicing. SIGNAL starts at index 2, CONFIRMED starts at index 11 (right after SIGNALxxx), and DELTA is the last 5 characters.
Code Runner Challenge
Popcorn Hack 1 - Extract the hidden message using indexing and slicing
View IPYNB Source
# CODE_RUNNER: Popcorn Hack 1 - Extract the hidden message using indexing and slicing
transmission = "xxSIGNALxxxCONFIRMEDxx77xxDELTA"
# SIGNAL starts at index 2 and is 6 characters long
word_1 = transmission[2:8]
print("Word 1:", word_1)
# CONFIRMED starts at index 11 and is 9 characters long
word_2 = transmission[11:20]
print("Word 2:", word_2)
# DELTA is the last 5 characters, so a negative slice grabs it
word_3 = transmission[-5:]
print("Word 3:", word_3)
print("Total length:", len(transmission))
# Every other character
print("Every other character:", transmission[::2])
Every other character: the step-2 slice scrambles the message. The output is xSGAxxOFREx7xDLA. Only broken pieces like SGA and DLA show up, so none of the hidden words can be read from this pattern.
Popcorn Hack 2: Scrub and Search a Noisy Transmission
Only string methods: .strip(), .replace(), .lower(), in, and .split().
Code Runner Challenge
Popcorn Hack 2 - Clean and search a noisy transmission using string methods
View IPYNB Source
# CODE_RUNNER: Popcorn Hack 2 - Clean and search a noisy transmission using string methods
noisy = " ...AGENT>>>Falcon---reports: the PACKAGE has ARRIVED!!! "
trimmed = noisy.strip()
print("Trimmed:", repr(trimmed))
cleaned = trimmed.replace(">", "").replace("-", "").replace("!", "")
print("Cleaned:", cleaned)
lowered = cleaned.lower()
print("Lowered:", lowered)
has_arrived = "arrived" in lowered
print("Contains 'arrived':", has_arrived)
words = cleaned.split()
print("Word count:", len(words))
Popcorn Hack 3: Build a Decoded Report
Concatenation with +, str() to turn the number into text, an f-string, and "-".join().
Code Runner Challenge
Popcorn Hack 3 - Build a decoded report using concatenation and formatting
View IPYNB Source
# CODE_RUNNER: Popcorn Hack 3 - Build a decoded report using concatenation and formatting
agent_name = "Falcon"
target_word = "MIDNIGHT"
confidence = 87
fragments = ["ALPHA", "SEVEN", "DELTA"]
headline = "Agent " + agent_name + " intercepted: " + target_word
print(headline)
confidence_line = "Confidence: " + str(confidence) + "%"
print(confidence_line)
confidence_line_fstring = f"Confidence: {confidence}%"
print(confidence_line_fstring)
joined_fragments = "-".join(fragments)
print("Joined fragments:", joined_fragments)
final_report = f"REPORT: {headline} | {confidence_line} | Fragments: {joined_fragments}"
print(final_report)
Homework: Crack the Final Transmission
The CSV row is stripped and split into 4 fields, and each field is pulled out by index. The date’s year is checked with a slice, and the message is cleaned and searched for “dawn”. Then the fields are rebuilt as a Markdown table row and a JSON-style line.
Code Runner Challenge
Homework - Crack the Final Transmission using slicing, methods, and formatting
View IPYNB Source
# CODE_RUNNER: Homework - Crack the Final Transmission using slicing, methods, and formatting
raw_transmission = " 2026-09-15,GHOST,THE-EAGLE-LANDS-AT-DAWN,87 "
# Strip the outer whitespace, then split the CSV row on commas
segments = raw_transmission.strip().split(",")
print("Segments:", segments)
# Pull each field out by its index
date = segments[0]
agent = segments[1]
message_code = segments[2]
confidence_str = segments[3]
print("Date:", date, "| Agent:", agent, "| Message code:", message_code, "| Confidence:", confidence_str)
# Slicing (not a method): the first 4 characters are the year
year_check = date[0:4] == "2026"
print("Year check:", year_check)
# Turn the dashes into spaces
message = message_code.replace("-", " ")
# Case-insensitive search for "dawn"
found_dawn = "dawn" in message.lower()
print("Found 'dawn':", found_dawn)
# Markdown table row
markdown_row = f"| {date} | {agent} | {message} | {confidence_str}% |"
print("Markdown row:", markdown_row)
# JSON-style line (JSON booleans are lowercase).
# The braces are stored in variables so the page never has two braces in a row.
open_brace = "{"
close_brace = "}"
json_line = f'{open_brace}"date": "{date}", "agent": "{agent}", "message": "{message}", "confidence": {confidence_str}, "contains_dawn": {str(found_dawn).lower()}{close_brace}'
print("JSON line:", json_line)