Arithmetic
Mathematics
Algorithms
Logic
Numbers
Input:
A list of length 1 to 10
Output:
The sum of the last two items of the list
Examples:
- [1,2] -> 3
- [-1,2] -> 1
- [2,2,-4] -> -2
- [4] -> 4
def sum_last_two_items(ls):
return ls[-1]+ls[-2] if len(ls)>1 else ls[0]
import codewars_test as test
# TODO Write tests
import solution # or from solution import example
# test.assert_equals(actual, expected, [optional] message)
@test.describe("Example")
def test_group():
@test.it("test case")
def test_case():
test.assert_equals(sum_last_two_items([1,2]), 3)
test.assert_equals(sum_last_two_items([-1,2]), 1)
test.assert_equals(sum_last_two_items([2,2,-4]), -2)
test.assert_equals(sum_last_two_items([9,4,2,6]), 8)
test.assert_equals(sum_last_two_items([0,0,0]), 0)
test.assert_equals(sum_last_two_items([-4,-8,-33]), -41)
test.assert_equals(sum_last_two_items([62738,74839]), 137577)