I am unable to produce any results with the following question:
Write a function named
append_sum
that has one parameter — a list named namedlst
. The function should add the last two elements oflst
together and append the result tolst
. It should do this process three times and then returnlst
. For example, iflst
started as[1, 1, 2]
, the final result should be[1, 1, 2, 3, 5, 8]
.
Here is my code:
#Write your function here
def append_sum(lst):
a = lst[-1] + lst[-2]
lst = lst.append(a)
return lst
#Uncomment the line below when your function is done
print(append_sum([1, 1, 2]))
I know I am not producing the results three times here but I would think this would return something. Instead it returns “None”.