The Longest Walk
The longest walk is a piece you can write without asking anyone. In the Python course, you found the largest value of a list by keeping the largest one so far, and the best day of a week by keeping the whole day, not only its number. Here it's the same with walks, and this exercise has no chat: the function is yours.
longest_walk(walks) should return the whole walk, the list with its day, dog and minutes, so that the report can say whose walk it was and on which day. For now, the program has a stand-in for it under earnings_per_dog() that returns the first walk, so that its test can run before you've written the function. Write the test first, as with the other pieces. In test_week, you can see the longest walk at a glance.
A test of your own code is worth as much as a test of an answer's. You know what you meant to write; the test checks what you did write.
Instructions
- 1
Under the other tests, write one for
longest_walk():print(longest_walk(test_week)[2] == …)with the minutes of the longest walk intest_week.[2]takes the minutes from the walk that the function returns. Run the program: the new test printsFalse, because the stand-in returns the first walk. - 2
Write the function
longest_walk(walks)in place of the stand-in. Then, at the end of the program, print the week's longest walk:Longest: 60 min (Rex, Wed). Run it: the new test printsTruenow.