Question: program is pycharm Part III: Count Pairs that Sum to a Third Value (15 points) Write a function pair.equals.sum() that counts how many pairs of
program is pycharm Part III: Count Pairs that Sum to a Third Value (15 points) Write a function pair.equals.sum() that counts how many pairs of integers - with each element of the pair CSE 101 - Spring 2020 Homework #2 taken from a different list - equal a particular sum when added. The sums to check are taken from a third list. The function takes the following arguments, in this order: nums 1: a list of integers that provides the first value in each pair nums 2: a list of integers that provides the second value in each pair sums a list of integers whose values might equal the sum of pairs of integers As an example of how this function works, suppose we have the following argument values: numal - 15, 3, 21 nums2 - 11, 1, 71 Bums - 6, 8, 9] First, observe that all three lists are of the same length. The function is guaranteed that the three lists always have the same length as each other. Second, note that nums 1[0] + nums210) equals sums [0], nums 1[1] + nums 2[1does not equal sums 11). and nums1[2] + nums 2 [2] equals sums (2). Since only two of the pairs sum to their corre- sponding value in sums, the return value will be 2. In general, the value from each "nums" list is summed. and the checks to see if that sum equals the value from the sums list. In the case where the three lists are empty, the function retums 0. Examples: Return Value 4) [1, 10, 5, 7) Function Argument [1, 3, 2), (1, 5, 6), 12, 8, [3, 7, 4, 5), (-2, 3, 1, 2), 01. 11. (1 16, 2, 3, 8, 9, 31, (-3, -6, [8, 6, 7, 5), (3, 0, 9, 2), 14, -4, -5, 11, 2, 4) 4 -8, (3, 3, 2, 6, 11, 1), 9]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
