Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
PYTHON DATA / CHAPTER 02 / Learn / LESSON 05
Fourth class. The list is ready. Now we want summaries: average, minimum, maximum — classic aggregates.
average = sum(weights) / len(weights). sum adds every item; dividing by len gives the mean. For the lesson data [70.0, 72.0, 74.0, 75.0] the average is 72.75.
minimum = min(weights) and maximum = max(weights) are built-in functions. Do not write a hand-rolled min/max loop unless a lesson asks for it — here the goal is to use the language tools.
Mini example:
vals = [3.0, 1.0, 2.0]
print(sum(vals) / len(vals))
print(min(vals))
print(max(vals))Print order matters for the checks: average, then minimum, then maximum — as in the task.
Common mistake: average = sum(weights) / 4 (a magic number instead of len); min/max on an empty list; printing only one of the three.
Learn: you write the list and the three aggregations.
AGGREGATE IDLE
›