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

Earnings per Dog

The next piece is what Mia earned for each dog. Write its tests first, as in Tests Come First: then the assistant knows exactly what the function has to return, and you know at once whether its answer does.

A test is only as good as the number in it, so work the numbers out carefully. Mia charges for each walk on its own, £6 for every started half hour of it. So in test_week, price each of Rex's walks as walk_price() would, then add the prices up. Adding up his minutes first and pricing the total gives another number, and it's the wrong one.

So that the tests can run before the function exists, the program has a stand-in under minutes_per_dog(): an earnings_per_dog() that returns the minutes, not the money. Its numbers are wrong on purpose, so your new tests print False until the real function takes its place. When they print True, you know it was the new function that made them pass.

Instructions

  1. 1

    Work out by hand what Mia earned for Rex and for Max in test_week. Under your two tests, write two more in the same way: print(earnings_per_dog(test_week)["Rex"] == …), and the same for Max. Run the program: the two new tests print False, because the stand-in returns minutes.

  2. 2

    Attach script.py and ask for the real earnings_per_dog(walks) in place of the stand-in: one that makes your tests print True, using walk_price(). Say that the rest of the program should stay as it is. Then send it.

  3. 3

    Paste the function from the answer in place of the stand-in and run the program: the four tests print True. Then add the earnings to the report: in the loop over the dogs, print what Mia earned for each one too, from earnings_per_dog(walks), so that the first line is Rex: 175 min, earned 42.

Back

2/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: