Popcorn Hack 1: Indexing & Slicing

# Popcorn Hack 1 - Extract the hidden message using indexing and slicing

transmission = "xxSIGNALxxxCONFIRMEDxx77xxDELTA"

# TODO 1: Use slicing to pull out "SIGNAL"
word_1 = transmission[2:8]
print("Word 1:", word_1)

# TODO 2: Use slicing to pull out "CONFIRMED" 
word_2 = transmission[11:20]
print("Word 2:", word_2)

# TODO 3: Use NEGATIVE indexing/slicing to pull out "DELTA"
word_3 = transmission[-5:]
print("Word 3:", word_3)

# TODO 4: Use len() to print how many characters are in the FULL transmission
print("Total length:", len(transmission))

# TODO 5: Use a slice with a step of 2 to print every other character
print("Every other character:", transmission[::2])
Word 1: SIGNAL
Word 2: CONFIRMED
Word 3: DELTA
Total length: 31
Every other character: xSGAxxOFREx7xDLA

Popcorn Hack 2: String Methods

# Popcorn Hack 2 - Clean and search a noisy transmission using string methods

noisy = " ...AGENT>>>Falcon---reports: the PACKAGE has ARRIVED!!! "

# TODO 1: Use .strip() to remove the leading/trailing whitespace
trimmed = noisy.strip()
print("Trimmed:", repr(trimmed))

# TODO 2: Use .replace() to remove ">", "-", and "!"
cleaned = trimmed.replace(">", "").replace("-", "").replace("!", "")
print("Cleaned:", cleaned)

# TODO 3: Use .lower() to make an all-lowercase COPY
lowered = cleaned.lower()
print("Lowered:", lowered)

# TODO 4: Use the 'in' operator to check for "arrived"
has_arrived = "arrived" in lowered
print("Contains 'arrived':", has_arrived)

# TODO 5: Use .split() with no arguments to break it into words
words = cleaned.split()
print("Word count:", len(words))
Trimmed: '...AGENT>>>Falcon---reports: the PACKAGE has ARRIVED!!!'
Cleaned: ...AGENTFalconreports: the PACKAGE has ARRIVED
Lowered: ...agentfalconreports: the package has arrived
Contains 'arrived': True
Word count: 5

Popcorn Hack 3: Concatenation & Formatting

# Popcorn Hack 3 - Build a decoded report using concatenation and formatting

agent_name = "Falcon"
target_word = "MIDNIGHT"
confidence = 87  
fragments = ["ALPHA", "SEVEN", "DELTA"]

# TODO 1: Use + concatenation
headline = "Agent " + agent_name + " intercepted: " + target_word
print(headline)

# TODO 2: Use str() and + concatenation
confidence_line = "Confidence: " + str(confidence) + "%"
print(confidence_line)

# TODO 3: Rewrite using an f-string
confidence_line_fstring = f"Confidence: {confidence}%"
print(confidence_line_fstring)

# TODO 4: Use "-".join(fragments)
joined_fragments = "-".join(fragments)
print("Joined fragments:", joined_fragments)

# TODO 5: Use an f-string to build ONE final report line
final_report = f"REPORT: {headline} | {confidence_line_fstring} | Fragments: {joined_fragments}"
print(final_report)
Agent Falcon intercepted: MIDNIGHT
Confidence: 87%
Confidence: 87%
Joined fragments: ALPHA-SEVEN-DELTA
REPORT: Agent Falcon intercepted: MIDNIGHT | Confidence: 87% | Fragments: ALPHA-SEVEN-DELTA

Homework

# Homework - Crack the Final Transmission using slicing, methods, and formatting

raw_transmission = " 2026-09-15, GHOST, THE-EAGLE-LANDS-AT-DAWN,87 "

# TODO 1: Clean and split. (Using list comprehension to strip each field cleanly)
segments = [piece.strip() for piece in raw_transmission.strip().split(",")]
print("Segments:", segments)

# TODO 2: Extract by 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)

# TODO 3: Slicing check for the year
year_check = date[:4]
print("Year check:", year_check)

# TODO 4: Clean the message code
message = message_code.replace("-", " ")

# TODO 5: Search the message
found_dawn = "dawn" in message.lower()
print("Found 'dawn':", found_dawn)

# TODO 6: Markdown table row formatting
markdown_row = f"| {date} | {agent} | {message} | {confidence_str}% |"
print("Markdown row:", markdown_row)

# TODO 7: JSON line formatting (forcing boolean to lowercase for JSON standards)
open_b = "{"
close_b = "}"

json_line = f'{open_b}"date": "{date}", "agent": "{agent}", "message": "{message}", "confidence": {confidence_str}, "contains_dawn": {str(found_dawn).lower()}{close_b}'
print("JSON line:", json_line)
Segments: ['2026-09-15', 'GHOST', 'THE-EAGLE-LANDS-AT-DAWN', '87']
Date: 2026-09-15 | Agent: GHOST | Message code: THE-EAGLE-LANDS-AT-DAWN | Confidence: 87
Year check: 2026
Found 'dawn': True
Markdown row: | 2026-09-15 | GHOST | THE EAGLE LANDS AT DAWN | 87% |
JSON line: {"date": "2026-09-15", "agent": "GHOST", "message": "THE EAGLE LANDS AT DAWN", "confidence": 87, "contains_dawn": true}