I want to write a function that takes a list of distinct positive integers and a target positive integer value, and then returns a list of the pairs of integers where each pair sums up to the target value.
This is my code but it only shows one pair of numbers:
def pairsum(list1, target):
for i in range(len(list1) -1):
for j in range(i + 1 ,len(list1)):
if list1[i]+ list1[j] == target:
return (list1[i], list1[j])
pairsum([3,2,6,1,5,4], 7)
When I call pairsum([3,2,6,1,5,4], 7)
the output is (3,4)
which should be [(1,6), (2,5), (3,4)]
. result should be in ascending order of the first element in each tuple. i am not allowed to imporst anything