The question is " Write a function named append_sum
that has one parameter — a list named named lst
.
The function should add the last two elements of lst
together and append the result to lst
."
My solution is following here:
def append_sum(lst):
x = lst.append(lst[-1] + lst[-2])
return x
print(append_sum([1, 1, 2]))
Instead of printing 3, ‘None’ get printed. Can someone help me in this regard?