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

Minutes per Dog

Time for another project. In this checkpoint, you'll build a report on Mia's week in pieces, as in Build in Small Steps, and give each piece a test before you rely on it, as in Tests Come First. The instructions say less than before about what to write; if you get stuck, look back at the lesson where you learned it.

The report will show how many minutes Mia walked each dog and what she earned for each, her longest walk and her busiest day. In the editor, walks has this week's walks, each a nested list of the day, the dog and the minutes, such as ["Mon", "Rex", 30]. walk_price() works out the price of one walk, £6 for every started half hour. And test_week is a week of three walks that Mia wrote for testing, short enough to work out by hand.

Mia asked for the first piece, the minutes per dog, and pasted the function from the answer she got: minutes_per_dog(). It works, and it counts with a dictionary, totals = {}, which you haven't learned. You could ask for it without one, as in Get Code Explained. But answers count things per name with a dictionary almost every time, the rest of the report needs one too, and the Python course teaches it right after Functions. So this time, learn it from the answer. Before you build on code, though, make sure you can read it.

Instructions

  1. 1

    Attach script.py, say what you know (lists and nested lists, if, loops and functions) and that dictionaries are new to you, and ask for minutes_per_dog() to be explained line by line, with what you know. Then send it.

  2. 2

    Now test it on test_week. Work out by hand how many minutes Rex and Max walked in it, and under test_week, write a test for each of them, such as print(minutes_per_dog(test_week)["Rex"] == …) with your number in place of the dots. ["Rex"] reads Rex's minutes from the dictionary that the function returns. Run the program: both tests print True. The check also runs them on a broken minutes_per_dog(), where a good test prints False.

Back

1/4

  1. 1. Minutes per Dog
  2. 2. Earnings per Dog
  3. 3. The Longest Walk
  4. 4. The Busiest Day
Next

Start programming for free

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

Or sign up with: