Built-in functions sum(), min() and max()

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Built-in functions sum(), min() and max()

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. Which line gives the total of all the values in the list marks?
A total = sum(marks)
B total = add(marks)
2. Which line finds the smallest value in the list scores?
A lowest = smallest(scores)
B lowest = min(scores)
3. Which line finds the largest value in the list scores?
A highest = max(scores)
B highest = largest(scores)
4. For the list [4, 9, 2], what does sum() return?
A 15
B 9
5. Why is total = sum(prices) often better than a for loop with a running total?
A It lets you add values that are not in a list
B It is shorter and clearer, with less code to get wrong

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1total = sum(scores) Asum() needs a single list (or other iterable) as its argument, not separate numbers. It should be sum([10, 20, 30]).
2lowest = min(scores) BSquare brackets were used instead of round brackets. A function call needs min(scores).
3Find the largest value in a list in one line instead of writing a loop CFinds the smallest value in the list scores and stores it in lowest
4Calculate an average by combining sum() with len() Dhighest = max(scores)
5total = sum(10, 20, 30) Eaverage = sum(scores) / len(scores)
6smallest = min[scores] FAdds up every number in the list scores and stores the total, with no loop needed

Definitions

sum(), min(), max()

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
scores = [72, 85, 90, 64] total = ___(scores)
2.
scores = [72, 85, 90, 64] lowest = ___(scores)
3.
scores = [72, 85, 90, 64] highest = ___(scores)
4.
prices = [4.5, 12, 7.25] print("Total:", sum(______))
5.
temps = [18, 24, 31, 22] spread = max(temps) _ min(temps)

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A marks = [72, 88, 65, 90]
B total = Sum(marks)
C print(total)
Question 2
A scores = [14, 9, 21, 17)
B lowest = min(scores)
C print(lowest)
Question 3
A temps = [18 25 31 22]
B hottest = max(temps)
C print(hottest)
Question 4
A points = [5, 8, 3, 9]
B total = sum(points)
C count = len(points)
D average = total * count
E print(average)
Question 5
A data = [12, 7, 19, 4]
B biggest = max(data)
C smallest = min(data)
D spread = smallest - biggest
E print(spread)

Answer Key

Built-in functions sum(), min() and max()
Section A: Quick Questions
Q1
A — total = sum(marks)
Q2
B — lowest = min(scores)
Q3
A — highest = max(scores)
Q4
A — 15
Q5
B — It is shorter and clearer, with less code to get wrong
Section B: Match the Pairs
Q1
total = sum(scores) → Adds up every number in the list scores and stores the total, with no loop needed
Q2
lowest = min(scores) → Finds the smallest value in the list scores and stores it in lowest
Q3
Find the largest value in a list in one line instead of writing a loop → highest = max(scores)
Q4
Calculate an average by combining sum() with len() → average = sum(scores) / len(scores)
Q5
total = sum(10, 20, 30) → sum() needs a single list (or other iterable) as its argument, not separate numbers. It should be sum([10, 20, 30]).
Q6
smallest = min[scores] → Square brackets were used instead of round brackets. A function call needs min(scores).
Section C: Definitions
Q1
sum(), min(), max() — Built-in functions that return the total, smallest and largest value in a list, replacing a hand-written loop with one short, clear line of code.
Section D: Fill in the Blanks
Q1
scores = [72, 85, 90, 64] total = sum(scores)
Q2
scores = [72, 85, 90, 64] lowest = min(scores)
Q3
scores = [72, 85, 90, 64] highest = max(scores)
Q4
prices = [4.5, 12, 7.25] print("Total:", sum(prices))
Q5
temps = [18, 24, 31, 22] spread = max(temps) - min(temps)
Section E: Spot the Error
Q1
B — Python is case-sensitive, so Sum is not the built-in function. It should be sum(marks) in lowercase.
Q2
A — The list opens with [ but closes with ), which is a syntax error. It should close with ].
Q3
A — List items must be separated by commas. It should be [18, 25, 31, 22].
Q4
D — An average is the total divided by the count, not multiplied. It should be total / count.
Q5
D — The spread is the largest value minus the smallest. The subtraction is reversed and gives a negative number. It should be biggest - smallest.