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
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 printFalse, because the stand-in returns minutes. - 2
Attach
script.pyand ask for the realearnings_per_dog(walks)in place of the stand-in: one that makes your tests printTrue, usingwalk_price(). Say that the rest of the program should stay as it is. Then send it. - 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, fromearnings_per_dog(walks), so that the first line isRex: 175 min, earned 42.