Skip to content

Add Two Digits

You are given a two-digit integer n. Return the sum of its digits.

Example

For n = 29, the output should be

add_two_digits(n) = 11

Solution

py
def add_two_digits(n):
    n = str(n)
    if len(n) == 1:
        return int(n)
    else:
        return int(n[0]) + int(n[1])


print(add_two_digits(29))

my thoughts are neither my employer's nor my wife's