Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

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: 87

On 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. 1

    Attach script.py and ask for a function print_weeks(weeks) that prints a line for each week. Give the first two lines as an example: Week 1 (135 min): 30 and Week 2 (80 min): 24. Then send it.

  2. 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, from Week 1 (135 min): 30 to Week 4 (85 min): 18. If the answer said what they would be, compare: one answer promised Week 3 (105 min): 30.

Back

1/6

  1. 1. The Invoice
  2. 2. Tests First
  3. 3. One Step at a Time
  4. 4. What the Test Shows
  5. 5. Feedback on Your Program
  6. 6. Congratulations!
Next

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with: