cart_total(items) that takes a list of (price, quantity) tuples and returns the total cost, without modifying the input list or any variable outside the function. Purity here means: same input always gives same output, and no external state is read or changed.cart_total([(100, 2), (50, 3)])
350
100*2 + 50*3 = 200 + 150 = 350.
cart_total([])
0
An empty cart totals to 0.
A generator expression like sum(p * q for p, q in items) avoids building intermediate lists or touching outside state.
An empty list should sum to 0 automatically via sum().