I've been asked to accept a list of integers (x), add the first value and the last value in the list, and then return an integer with the sum. I've used the following code to do that, but the problem I have is that when I try to evaluate the sum it's actually a one-item list instead of an integer. I've tried to cast it to an int but I can't seem to get it to work.
def addFirstAndLast(x):
lengthOfList = len(x)
firstDigit = x[0:1]
lastDigit = x[lengthOfList:lengthOfList-1]
sum = firstDigit + lastDigit
return sum