Exercises
For this chapter’s exercises, you will again be working with existing files. I have a special talent for writing buggy code, and I’ve created just the right snippets for you to practice your debugging skills with. Each exercise includes its code right here. But I’m not going to ask you to debug it by staring at it. That was never a debug technique we discussed. That’s why I recommend downloading the files from our GitHub repository. By now, I trust you know where to find it.
10.1 Buggy cat naps
We’ve written a program to calculate the total time your cat sleeps in a day. But something seems off... The total that our function returns doesn’t match the actual time the cat spent napping:
def nap_time(hours_list):
total = 0
counter = 1
while counter < len(hours_list):
total += hours_list[counter]
counter += 1
return total
cat_naps = [2, 3, 1.5, 4]
print("Total nap time:", nap_time...