The Invoice
Welcome to the final project of Programming with AI! In it, you'll build one program from start to finish with the AI beside you: the invoice Mia sends Mrs Carter for the walks in May. When it's done, it prints this:
Invoice: Mrs Carter, May
Week 1 (135 min): 30
Week 2 (80 min): 24
Week 3 (105 min): 24
Week 4 (85 min): 18
Walks: 10
Time: 6 h 45 min
Total: 96
Discount: 9
To pay: 87On the way, you'll use what the course has taught you: you'll describe what you need with an example, write the tests before the code, build the program one step at a time, find a mistake that a test shows, and ask for feedback on your program. Each exercise continues where the previous one ended, and the editor starts with its finished program. Yours may be written differently; that's fine as long as it prints the same.
The program in the editor has the month in it. weeks is a list of four weeks, and each week is a list of its walks, in minutes. walk_price() is the function you've known since the first lesson: £6 for every started half hour. Mia prices each walk on its own, and in the second week that matters. Its two walks of 40 minutes make 80 minutes, which is three started half hours, or £18. But each walk has started a second half hour of its own, so each costs £12, and the week £24.
The first step is a line for each week. Asked for a line with each week's minutes and price, the AI decides what it looks like. Without an example, answers printed Week 1: 135 minutes, £30, and one of them priced each week's minutes together: Week 2: 80 minutes, £18. An example settles both. Give the first two lines exactly as they should look.
Instructions
- 1
Attach
script.pyand ask for a functionprint_weeks(weeks)that prints a line for each week. Give the first two lines as an example:Week 1 (135 min): 30andWeek 2 (80 min): 24. Then send it. - 2
Copy the function from the answer (only the function, if the answer has more) and paste it above the line that prints the heading. Under that line, call
print_weeks(weeks). Run the program: under the heading, it prints the four weeks, fromWeek 1 (135 min): 30toWeek 4 (85 min): 18. If the answer said what they would be, compare: one answer promisedWeek 3 (105 min): 30.