Skip to content

Instantly share code, notes, and snippets.

@JohnsonLuu
Last active June 2, 2020 15:43
Show Gist options
  • Save JohnsonLuu/897fc683038033c72a9ef13edcecbf8b to your computer and use it in GitHub Desktop.
Save JohnsonLuu/897fc683038033c72a9ef13edcecbf8b to your computer and use it in GitHub Desktop.
"""
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. It should do this process three times and then return lst.
For example, if lst started as [1, 1, 2], the final result should be [1, 1, 2, 3, 5, 8].
"""
#Write your function here
def append_sum(lst):
lst.append(lst[-2] + lst[-1])
lst.append(lst[-2] + lst[-1])
lst.append(lst[-2] + lst[-1])
return lst
#Uncomment the line below when your function is done
print(append_sum([1, 1, 2]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment