Hi all, I'm fairly new to python and I'm stuck with a problem. What I'm trying to do is write a recursive function that takes a list of integers and returns true if the list contains a single pair of integers whose sum is negative, and false otherwise. For example:
[13, 9, 15, -10, 11] would return True, because 9 + -10 is a negative number
[12, 8, 9, 17, -3] would return False, because no single pair of integers added up would result in a negative number.
What I have so far:
def neg_sum(L): if len(L) == 2: if L + L < 0: return True else: return False else:
I'm not quite sure what to write after this, I know that if the list has a length of 2, then all you need to do is add the two elements, and you see if the sum is negative or positive. However, if the list is larger than 2, I have to make a recursive call, which is where I'm getting confused. Anyone have some tips?