# 10 examples of 'python program to find sum of 3 numbers' in Python

Every line of 'python program to find sum of 3 numbers' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

## All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
``59def threeSum_2(self, numbers):6061    if not numbers or len(numbers) < 3:62        return []6364    results = []65    numbers.sort()6667    for i in range(len(numbers) - 2):68        if i == 0 or numbers[i] != numbers[i - 1]:69            target = -numbers[i]7071            left = i + 172            right = len(numbers) - 17374            while left < right:75                total = numbers[left] + numbers[right]7677                if total < target:78                    left += 17980                elif total > target:81                    right -= 18283                else:8485                    results.append([numbers[i], numbers[left], numbers[right]])86                    left += 187                    right -= 18889                    while left < right and numbers[left - 1] == numbers[left]:90                        left += 19192                    while left < right and numbers[right] == numbers[right + 1]:93                        right -= 19495    return results``
``23def threeSum(self, nums):24    """25    :type nums: List[int]26    :rtype: List[List[int]]27    """28    nums.sort()29    res = []3031    for i in range(len(nums)-1):  # because sums of 3 numbers32        if i == 0 or i > 0 and nums[i-1] != nums[i]:33        # avoid duplicate triplets [1 ,1, 1, -2]34            left = i + 135            right = len(nums) - 136            while left < right:   # two-way pointer37                s = nums[i] + nums[left] + nums[right]38                if s == 0:39                    res.append([nums[i], nums[left], nums[right]])40                    left += 141                    right -= 142                    while left < right and nums[left] == nums[left - 1]:43                        left += 144                    while right > left and nums[right] == nums[right + 1]:45                        right -= 146                elif s < 0:47                    left += 148                else:49                    right -= 150    return res``
``16def main():17    n = int(input())18    print(sum(get_digit(n)))``
``2def singleNumber(self, nums: List[int]) -> int:3    start = nums[0]4    for val in nums[1:]:5        start ^= val6    7    return start``
``29def main():30    print "source include/have_tokudb.inc;"31    print "# this test is generated by change_int_rename.py"32    print "--disable_warnings"33    print "DROP TABLE IF EXISTS t, ti;"34    print "--enable_warnings"35    print "SET SESSION DEFAULT_STORAGE_ENGINE=\"TokuDB\";"36    print "SET SESSION TOKUDB_DISABLE_SLOW_ALTER=1;"37    gen_test(38        [ "TINYINT", "SMALLINT", "MEDIUMINT", "INT", "BIGINT" ], 39        [ [ -128, -1, 0, 1, 127 ], [ -32768, -1, 0, 1, 32767], [-8388608, -1, 0, 1, 8388607], [-2147483648, 0, 1, 2147483647], [-9223372036854775808, 0, 1, 9223372036854775807] ]40    )41    gen_test(42        [ "TINYINT UNSIGNED", "SMALLINT UNSIGNED", "MEDIUMINT UNSIGNED", "INT UNSIGNED", "BIGINT UNSIGNED" ],43        [ [ 0, 1, 255 ], [ 0, 1, 65535], [0, 1, 16777215], [0, 1, 4294967295], [0, 1, 18446744073709551615] ]44    )45    return 0``
``32def main():33    f = fac(N)34    d('factorial(%i)=%i' %(N, f))35    #s = digitsum(f)36    s = sum([int(i) for i in str(f)])37    print(s)``
``9def consecutive_sum(number):10    if number // 10 < 1:11        return number12    return number % 10 + consecutive_sum(number // 10)``
``17def my_sum(a, b):18    print("a + b = %d" % (a + b))``
``34def listsum(numList):35    if len(numList) == 1:36        return numList[0]37    else:38        return numList[0] + listsum(numList[1:])``
``3def threeSum(self, num):4  num = sorted(num)5  res = []6  i = 07  while i < len(num) - 2:8    j = i + 19    k = len(num) - 110    while j < k:11      sum = num[i] + num[j] + num[k]12      if sum == 0:13        res.append([num[i], num[j], num[k]])14        j, k = j + 1, k - 115        while j < k and num[j] == num[j - 1]:16          j += 117        while j < k and num[k] == num[k + 1]:18          k -= 119      elif sum < 0:20        j += 121      else:22        k -= 123    i += 124    while i < len(num) - 2 and num[i] == num[i - 1]:25      i += 126      27  return res``