Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Finding if 2 consecutive numbers in a list have a sum equal to a given number

def sum_finder(num_list, sum):

    for num in num_list:
        
        if((num_list.index(num) + 1) >= len(num_list)):
            return False
        
        if((num + num_list[num_list.index(num) + 1]) == sum):
            print(num, (num_list[num_list.index(num) + 1]))
            return True
 
PREVIOUS NEXT
Tagged: #Finding #consecutive #numbers #list #sum #equal #number
ADD COMMENT
Topic
Name
6+7 =