Three Dogs
Mia often takes two or three dogs on the same walk, and then the others pay less. Her rule: the first dog pays the full price, and every other dog on the walk pays half of it. So 45 minutes cost 12 for Rex alone, 12 + 6 = 18 for Rex and Bella, and 12 + 6 + 6 = 24 for all three.
She asked an assistant for a function and pasted the one she got into the program, under walk_price(), with two lines that print its prices for one dog and for two. Both prices are right. Her message said:
Write a function dogs_price(minutes, dogs) that returns the price of a walk with several dogs. Use walk_price(minutes) for the first dog. A second dog on the same walk costs half. Example: 45 minutes with two dogs cost 18.Her message named one dog and two, and the two lines try only those. A function can be right for every example you gave it and wrong for a case nobody named, and here there is one: three dogs, which Mia walks together every Saturday. That's the case to try before the price list relies on the function.
When you aren't sure which cases are left to try, the assistant can list them: attach the program and ask. The answers we got named three dogs, and said to check the price the function gives for them against Mia's rule, which they didn't know.
Instructions
- 1
Under the two lines that print the prices of
dogs_price(), add one in the same way for Saturday's walk, 30 minutes with all three dogs, labeled30 min, 3 dogs:. Run the program. By Mia's rule, the walk costs 6 + 3 + 3 = 12, but the last line says30 min, 3 dogs: 9.