Rocket runs an early version of the planner. It says Moon hop needs 900 units of fuel! "That is impossible," he says. "The whole station only has 120."
Then a second problem appears. The Ring tour is missing from the board, even though the log says it is ready. Raven gets out her notepad. "What do you notice? Two bugs, two clues."
Nova highlights the decode function. "Let's debug together. Would you like a hint? Check which piece goes with which key."
def decode(line):
parts = line.split(";")
return {"name": parts[0], "time": parts[3], "fuel": int(parts[2])}
launch = decode("Moon hop;2;0900;30;READY")
print(launch["name"], "needs", launch["fuel"])
print("Time:", launch["time"]) | The screen shows |
|---|
| Moon hop needs 900 |
| Time: 30 |
| Index | 0 | 1 | 2 | 3 | 4 |
|---|---|---|---|---|---|
| Piece | Moon hop | 2 | 0900 | 30 | READY |
int("0900") is 900. The fuel and the time were read from the wrong pieces.
log = ["Ring tour;7;1400;25;ready", "Comet chase;5;1600;40;READY"]
count = 0
for line in log:
parts = line.split(";")
status = parts[4]
if status == "READY":
count = count + 1
print(count, "ready") | The screen shows |
|---|
| 1 ready |
log = ["Moon hop;2;0900;30;READY", "Mars run;4;1100;70;HOLD"]
total = 0
for line in log:
parts = line.split(";")
total = total + int(parts[3])
print("Ready fuel:", total) | Change to the fixed program | Does it still show 30? |
|---|---|
| Change Mars run to READY | ? |
| Add "Sun watch;1;1800;30;HOLD" to the log | ? |
| Change the Moon hop fuel to 35 | ? |
| Rename total to need on every line | ? |
Both bugs are squashed! Tomorrow is launch day. You will run the whole planner.