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

One Piece at a Time

The program in the editor is the one from the last exercise, with total_minutes() and the line that prints it. That piece is done: you ran it and checked the 190 minutes by hand. Now comes the next piece, in the same way.

Running the program after every piece is what makes small steps worth it. Everything you added before was checked when you added it, so when a line of the report comes out wrong, the mistake is in the piece you've just added. In a program pasted in one go, it could be in any line.

This exercise has a chat of its own, which hasn't seen the program or the plan. That doesn't matter: attach the program as it is now, and say which piece you want. The next one is what Mia earned, the price of each walk added up. walk_price() already works out the price of one walk, so the new function only has to call it for every walk.

Instructions

  1. 1

    Attach script.py and ask for only the next piece: a function week_total(walks) that returns what Mia earned, using walk_price() for every walk. Say that you want nothing for the longest walk yet. Then send it.

  2. 2

    Paste the function into the editor above print_report(), and add print("Total:", week_total(walks)) at the end of print_report(). Run the program and check the new line by hand: the walks cost 6, 12, 6, 12 and 12, so it prints Total: 48.

Back

2/7

  1. 1. A Plan Before Code
  2. 2. One Piece at a Time
  3. 3. Quiz: The Piece Just Added
  4. 4. Leave the Rest as It Is
  5. 5. A New Chat
  6. 6. Quiz: A Long Chat
  7. 7. Summary
Next

Start programming for free

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

Or sign up with: