# Write a function, called check24, # that takes a list of arbitrary, unsorted integers that are less than 20 # and decides if any of the two numbers in the list sum to 24. # The function will return 2 things (in order): # 1. A list of strings of the two-numbers pairs that sum to 24. If no pairs sum to 24, return an empty list # 2. The number of the two-number pairs returned # (hint: this is a multi return function) # # A sample run would be # # print(check24([12, 16, 8, 19, 5])) # [16-8, 19-5], 2 # note: 16-8 is the same as 8-16, thus return once # # You may assume the list is non-empty, will only contain integers, no tie. def check24(lst): result = [] number_pairs = 0 for i in range(0, len(lst)): for j in range(i+1, len(lst)): if (lst[i] + lst[j]) == 24: #print(str(lst[i]) + " + " + str(lst[j]) + " = " + str(lst[i]+lst[j])) # check if a pair is already in result if (not ((str(lst[i]) + "-" + str(lst[j])) in result)) and \ (not ((str(lst[j]) + "-" + str(lst[i])) in result)): result.append(str(lst[i]) + "-" + str(lst[j])) return result, len(result) print(check24([12, 16, 8, 19, 5])) print(check24([5, 7, 2, 14])) print(check24([-2, 0, 26, -5]))