Search⌘ K
AI Features

Solution Review: Check Sum

Understand how to implement nested loops in Python to find all possible pairs in a list for the Check Sum problem. This lesson reinforces Python basics such as loops and the range function, preparing you for deeper topics like arrays.

We'll cover the following...

Solution

Python 3.5
def check_sum(num_list, num):
for first_num in range(len(num_list)):
for second_num in range(first_num + 1, len(num_list)):
if num_list[first_num] + num_list[second_num] == num:
return True
return False
num_list = [10, -14, 26, 5, -3, 13, -5]
print (check_sum(num_list, -8))
...