Sum of pair products
Inputs
values is a list of 0 to 10 whole numbers, each from -5 to 9.
Your tasks
- Create a number
totalthat starts at 0. - Use nested loops over every pair of positions
i < j. Addvalues[i] * values[j]tototal. - Complete
pairProductsso it returnstotal. Return it, do not print it.
Example
With values = [1, 2, 3], pairProducts returns 11.
Rules
- Each pair is used once.
Test data
TEST DATA 1: values is [1, 2, 3]
TEST DATA 2: values is []
Practice focus
Nested loops compare every pair and build rows. The slow, simple answer to most problems is two loops. Knowing it is what lets you see how to beat it.