Who Belongs to the Family?

Python for AIMedium+10 XP+10

Who Belongs to the Family?

A zoo's inventory holds all sorts of things. The starter code has four classes: Animal, Dog (a child of Animal), Puppy (a child of Dog), and Robot (no parent). Don't change them.

Write family_report(things). It returns a dictionary with three counts:

  • "animals": how many things are an Animal or any child of it,
  • "dogs": how many are a Dog or any child of it,
  • "others": how many are not an Animal at all.

The list can contain anything, including text and numbers. An empty list gives all three counts as 0.

Examples

things = [Dog("Rex"), Robot("Unit 7")]
returns {'animals': 1, 'dogs': 1, 'others': 1}
things = [Dog("Rex"), Puppy("Bud"), Robot("Unit 7"), Animal("Ada")]
returns {'animals': 3, 'dogs': 2, 'others': 1}

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run