Sign in to track progress, unlock prep layers, and browse your pipeline.Sign in
Implement Safe Average Function
Implement Safe Average Function
Write a Python function named average(values) that calculates and returns the arithmetic mean of a given list of numbers.
Requirements
- If the input list
valuesis empty, the function must return0. - The input
valueswill be a flat list containing only numeric types (integers or floats). - The function must not modify (mutate) the original input list.
Examples
average([1, 2, 3])should return2.0average([-1, 1])should return0.0average([])should return0
AI interview prep
Core dilemma
Achieving numerical accuracy and robustness across diverse input scales and types, while maintaining efficiency, for a seemingly simple arithmetic operation.
Mid-level signals3
Senior signals3
Red flags3
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Implement Safe Average Function
Implement Safe Average Function
Write a Python function named average(values) that calculates and returns the arithmetic mean of a given list of numbers.
Requirements
- If the input list
valuesis empty, the function must return0. - The input
valueswill be a flat list containing only numeric types (integers or floats). - The function must not modify (mutate) the original input list.
Examples
average([1, 2, 3])should return2.0average([-1, 1])should return0.0average([])should return0