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."
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.
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)) | Statement | True or false? |
|---|---|
| The loop splits every line. | ? |
| HOLD launches are added to names. | ? |
| names starts empty. | ? |
| parts[0] is the gate. | ? |
The schedule works! Tomorrow you will check the fuel budget.