I got an assignment in my CS class: to find pairs of numbers in a list, that add to a number n, that is given. This is the code I wrote for it:
def pair (n, num_list):
"""
this function return the pairs of numbers that add to the value n.
param: n: the value which the pairs need to add to.
param: num_list: a list of numbers.
return: a list of all the pairs that add to n.
"""
for i in num_list:
for j in num_list:
if i + j == n:
return [i,j]
continue
When I try to run it, I'm given the following message:
TypeError("'int' object is not iterable",)
What is the problem? I can't find a place in which I use a list
obj as an int
, or vice versa.