Codewars logo

Codewars Kata — Sum of two lowest positive integers

By Lochard | As a newbie programmer | 19 Aug 2023


Create a function that returns the sum of the two lowest positive numbers given an array of minimum 4 positive integers. No floats or non-positive integers will be passed.

 

For example, when an array is passed like [19, 5, 42, 2, 77], the output should be 7.

 

[10, 343445353, 3453445, 3453545353453] should return 3453455.

def sum_two_smallest_numbers( numbers ):
    return sum( sorted( numbers )[ : 2 ] )

How do you rate this article?

1


Lochard
Lochard

20240228 Arrived in the UK for about 2 week. All my fears persist. Some are even getting worse. https://github.com/locharp/asylum_diary/


As a newbie programmer
As a newbie programmer

Sharing entry level codes. My snippets on GitHub https://github.com/locharp/code-snippets

Publish0x

Send a $0.01 microtip in crypto to the author, and earn yourself as you read!

20% to author / 80% to me.
We pay the tips from our rewards pool.