Want to break the following code so that my functions are no larger than 10 statements def monthly_averages(records): """monthly averages""" list_of_average_steps_per_month = [] for month in range(1, 13): steps_for_month = [] for date, steps in records: rec_month = int(date[5:7]) if rec_month == month: steps_for_month.append(steps) if len(steps_for_month) > 0: average_steps_per_month = sum(steps_for_month) / len(steps_for_month) list_of_average_steps_per_month.append(average_steps_per_month) else: list_of_average_steps_per_month.append(-1) return list_of_average_steps_per_month
def getAverageStepsPerMonth(steps_for_month): if len(steps_for_month) > 0: return sum(steps_for_month) / len(steps_for_month) else: return -1 def getStepsPerMonth(records, month): steps_for_month = [] for date, steps in records: rec_month = int(date[5:7]) if rec_month == month: steps_for_month.append(steps) return steps_for_month def monthly_averages(records): """monthly averages""" list_of_average_steps_per_month = [] for month in range(1, 13): steps_for_month = getStepsPerMonth(records, month) list_of_average_steps_per_month.append(getAverageStepsPerMonth(steps_for_month)) return list_of_average_steps_per_month
Get Answers For Free
Most questions answered within 1 hours.