runtime
402 / 500
question 402 NumPy Foundations · easy

The average fare that crashes on cents

average_fare should return the mean of a list of fares that arrive as text. It works for ["40", "7"] but crashes with ValueError as soon as a fare has cents, and for an empty list it should return None instead of a warning and nan. Fix it.

Functionaverage_fare(fares)
faresa list of texts such as "17.2"
Returnsthe mean fare as a float, or None for an empty list
Examples
callaverage_fare(['40.8', '7.2', '17.2'])returns21.733333333333334
callaverage_fare(['40', '7'])returns23.5
callaverage_fare([])returnsNone

Loading your progress…

The average fare that crashes on cents — Python practice · Runtime