From 5898682bae3fc1942de340d2c6161c15ed3f63a5 Mon Sep 17 00:00:00 2001 From: Josh Mudge Date: Fri, 11 Jan 2019 23:59:49 -0700 Subject: [PATCH] Add the last two elements, append them. --- Codecademy.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Codecademy.md b/Codecademy.md index 80b2f73..041e243 100644 --- a/Codecademy.md +++ b/Codecademy.md @@ -355,6 +355,26 @@ elif len(lst) % 2 == 0: print(middle_element([5, 2, -10, -4, 4, 5, 7])) ``` +### Add the last two elements, append them. (Ex.8) + + ``` + def append_sum(lst): + trip = 0 + + while trip < 3: + lasttwo = lst[-2:] + added = lasttwo[0] + lasttwo[1] + print(added) + lst.append(added) + + trip = trip + 1 + + return lst + +#Uncomment the line below when your function is done +print(append_sum([1, 1, 2])) +``` + ### Sublists Grab a subset of a list using `sublist = letters[1:6]` This would give you index **1-5**.