← Back to course
Code Crew G4 / Week 12 / Tuesday
2/6
Week 12 Β· Launch day

Tuesday

Build the schedule
// Build the launch planner
⏱ about 15 min

Tuesday: Build the schedule

The decode piece works. Now Rocket needs the whole schedule. The comms log has four entries, but one launch is on hold for repairs.

"I will decode them all and print them all," Rocket says. Raven shakes her head gently. "What do you notice? The pilots only want the ready ones on the board."

Nova makes the held launch fade to gray. "Would you like a hint? You filtered records in week eight. Decode, check, append."

Piece 2: keep the ready launches

def decode(line):
    parts = line.split(";")
    return {
        "name": parts[0],
        "gate": parts[1],
        "time": parts[2],
        "fuel": int(parts[3]),
        "status": parts[4].upper(),
    }

log = [
    "Moon hop;2;0900;30;READY",
    "Mars run;4;1100;70;HOLD",
    "Ring tour;7;1400;25;ready",
    "Comet chase;5;1600;40;READY",
]
ready = []
for line in log:
    launch = decode(line)
    if launch["status"] == "READY":
        ready.append(launch)
for launch in ready:
    print(launch["time"], launch["name"], "gate", launch["gate"])
print("Next up:", ready[0]["name"])
The screen shows
0900 Moon hop gate 2
1400 Ring tour gate 7
1600 Comet chase gate 5
Next up: Moon hop

The log is already in time order, so ready[0] is the next launch.

How many records are in ready?
Which launch is left off the board?
WHAT IF?
  • Read the question.
  • Tap your answer.
Moon hop changes to HOLD. What shows after Next up:?
How many lines would the board print then, before Next up:?
Try it
Write two log entries of your own, with the same five pieces.
Mark one READY and one HOLD.

Practice lab: a new log

log = ["Probe;3;0800;20;READY", "Relay;6;1000;15;HOLD", "Scout;1;1200;35;READY"]
names = []
for line in log:
    parts = line.split(";")
    if parts[4] == "READY":
        names.append(parts[0])
print(len(names), "ready")
print("Board:", ", ".join(names))
What number is on the first screen line?
What is the first name after Board:?
Which launch is on hold?
SCHEDULE CHECK
  • Read the question.
  • Tap your answer.
Which index holds the status?
Relay changes to READY. How many launches are ready?
What does ", ".join(names) do?
StatementTrue or false?
The loop splits every line.?
HOLD launches are added to names.?
names starts empty.?
parts[0] is the gate.?
WHY THIS EXERCISEEvery line is checked, but only matches are kept.
What is the gate of the Scout launch?
WHY THIS EXERCISEScout;1;1200;35;READY has gate 1.
Try it
Write the three log lines on scraps of paper.
Be the loop: keep the READY scraps in one pile.
Read the names in the pile, with commas between them.

The schedule works! Tomorrow you will check the fuel budget.

← Monday