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
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 saysTotal: 50: a walk is missing. - 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 listmonthas they are: the exercise runs your program with other walks too. The program printsTotal: 1165andTotal: 60.