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

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. 1

    Under the other tests, write one for longest_walk(): print(longest_walk(test_week)[2] == …) with the minutes of the longest walk in test_week. [2] takes the minutes from the walk that the function returns. Run the program: the new test prints False, because the stand-in returns the first walk.

  2. 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 prints True now.

Back

3/4

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

Try it yourself

Do this exercise right here in your browser. No account needed.