I am going through the challenges and passed the verification with my answer. However, I know there is a better way to do this (loops). Could anyone show me a simpler way to do this? Thanks!
Write a function named
append_sumthat has one parameter — a list named named
The function should add the last two elements of
lsttogether and append the result to
lst. It should do this process three times and then return
For example, if
[1, 1, 2], the final result should be
[1, 1, 2, 3, 5, 8].
#Write your function here def append_sum(lst): addition = lst[-1] + lst[-2] lst.append(addition) addition2 = lst[-1] + lst[-2] lst.append(addition2) addition3 = lst[-1] + lst[-2] lst.append(addition3) return lst #Uncomment the line below when your function is done print(append_sum([1, 1, 2]))