Reading a Change
When an agent has done a task, read what it changed before you keep it. Agents and code editors show a change line by line: a line that starts with - was taken out, a line that starts with + was put in, and the lines around them show where. Many show them in red and green.
This is a change of the kind agents make, for the discount from What a Coding Agent Does. The agent's summary said only: “I added the discount and ran the program: it prints Total: 37.”
def walk_price(minutes):
half_hours = minutes // 30
- if minutes % 30 > 0:
+ if minutes % 30 >= 15:
half_hours = half_hours + 1
return half_hours * 6
walks = [45, 30, 75, 20]
total = 0
for minutes in walks:
total = total + walk_price(minutes)
+if len(walks) > 3:
+ total = total - 5
+
print("Walks:", len(walks))
print("Total:", total)The lines it put in near the end are the discount. But it also changed a line in walk_price(), which nobody asked for. Agents do that: they tidy up code that works, rename what you named, or “fix” what they take for a mistake. A change you didn't ask for isn't always wrong, but it's yours to decide on, and this one changes Mia's prices.
The program still prints Walks: 4 and Total: 37, as the agent said: with these four walks, both versions of the line give the same prices. Running the program didn't show the change; reading it did. The program in the editor is the agent's version.
Instructions
- 1
Find out what the line nobody asked for does to the price: at the end of the program, add
print("Price:", walk_price(40)), which prints the price of a 40-minute walk, and run it. A walk of 40 minutes has started its second half hour, so it should cost 12, but the agent's version printsPrice: 6. - 2
Put the line back as it was before the change, and keep the discount. Run the program: it prints
Walks: 4,Total: 37andPrice: 12.