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

A Result That Looks Right

Some mistakes show at once: an error, or 18 for a walk that costs 12. Others hide in a number that looks fine.

Mia wants to know how many minutes she spent walking dogs this month. The program in the editor adds up her thirty walks with a function someone got from an AI, one answer of many, and prints a total of over a thousand minutes. Thirty walks of 20 to 60 minutes each: that sounds about right. But is it?

You can't tell by looking, and adding thirty numbers in your head is no check either: you'd be as likely to slip. Try the function on numbers small enough to add up yourself, such as 10, 20 and 30, which make 60. It adds three numbers the same way it adds thirty, so a mistake in how it adds shows up on three as well, where you can see it.

Instructions

  1. 1

    Run the program and look at the total. Then check the function on three walks you can add up: below the line that prints, add print("Total:", total_minutes([10, 20, 30])) and run it again. The walks make 60, but the second line says Total: 50: a walk is missing.

  2. 2

    Which walk is missing, the 10, the 20 or the 30? Find the line that leaves it out and fix total_minutes() so that it adds every walk in the list. Keep the lines of the list month as they are: the exercise runs your program with other walks too. The program prints Total: 1165 and Total: 60.

Back

4/6

  1. 1. It Runs, and It's Wrong
  2. 2. Quiz: At Least 30 Minutes
  3. 3. The Cases Nobody Asked About
  4. 4. A Result That Looks Right
  5. 5. Quiz: The Limit
  6. 6. Summary
Next

Try it yourself

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