Python lesson
sum(), min(), max()
sum adds every item: 611. min finds the smallest (96) and max the biggest (175). Like len, they take the list inside their brackets.
Try this lesson free →Example
Three more built-in tools work on a list of numbers:
sales = [96, 120, 175, 120, 100]
print(sum(sales))
print(min(sales))
print(max(sales))611
96
175Key points
sum(sales)Adds up every number in the list.
min(sales)The smallest number.
max(sales)The biggest number.
Put together: sum(sales) / len(sales) is the average: the total divided by how many.
Practice
1. Build a line that shows the total of prices.
print(sum(prices))2. Build a line that stores the biggest sale in a variable called best.
best = max(sales)3. Print the total of all the sales.
sales = [96, 120, 175, 120, 100]
print(sum(sales))4. Print the smallest sale.
sales = [96, 120, 175, 120, 100]
print(min(sales))5. Print the average sale: the total divided by how many sales there are.
sales = [96, 120, 175, 120, 100]
print(sum(sales) / len(sales))Learn it by doing. This lesson is a short hands-on level on Bampaa: see it work, then build and write it yourself, with instant feedback.
Try this lesson free →