Code Review #1
Review this Python function and identify all issues: ```python def get_cat_ages(cats): ages = [] for i in range(len(cats)): if cats[i]["age"] > 0: ages.append(cats[i]["age"]) else: ages.append("unknown") return sum(ages) / len(ages) ``` List each bug, explain why it's a problem, and provide a corrected version.
Judge: Finds all the major bugs (int/str sum TypeError, ZeroDivisionError, KeyError, skewed average from placeholder values) plus the age-0 edge case, misleading name, and unidiomatic loop. The corrected version excludes invalid ages, guards the empty case, uses .get, and is verified by a worked example. Explanations are precise and genuinely instructive.
