A Plan Before Code
Ask an assistant for a whole program, and you get it all at once. Asked for Mia's whole report, with the program attached, one answer wrote all of it in one go. It was right, but it worked out what Mia earned with sum(walk_price(m) for m in walks), which you haven't learned, and so did the other answers to the same message. To trust a program you get in one piece, you have to check all of it at once, and when it prints a wrong total, the mistake could be in any line.
So programmers build a program in small steps: one piece, run it and check it, then the next. Before the first piece comes a plan: the steps in order, each small enough to write and check on its own. A plan in words takes a minute to read, and while there's no code yet, it's easy to change.
An assistant writes good plans, but it likes to put code into them. Say that you don't want any code yet. Then ask for the code of one step, and only that one.
Mia wants a report of her week: how many walks, how many minutes in all, what she earned and the longest walk. The program in the editor has walk_price(), which charges £6 for every started half hour, this week's walks, and print_report(), which prints the report's first line so far.
Instructions
- 1
Attach
script.pyand change the message: keep what the report should show, and ask for a plan instead of the program, with the steps in order, numbered, each small enough to write and check on its own. Say that you don't want any code yet. Then send it. - 2
Now ask in the same chat for the code of one step only: the one that adds up the minutes, as a function
total_minutes(walks)that returns the minutes of all the walks. Say that you want nothing for the other steps yet. - 3
Copy the function from the answer and paste it into the editor above
print_report(). Then add a line at the end ofprint_report():print("Time:", total_minutes(walks), "min"). Run the program. It printsWalks: 5andTime: 190 min: check the minutes by hand.