Hello,
I am new to Python and am currently taking Codecademy’s Python 3 course. I am having difficulty completing one code challenge that requires returning a loop within a function.
The challenge requires defining a function that adds the last two elements of the list together, and then appends that summation to the end of the same list. I was able to do this:
def append_sum(lst):
lst.append(lst[-1] + lst[-2])
return lst
However, the challenge also requires the function to return the appended list three times, using a loop function. Here is what I have tried so far, however I continue to receive a syntax error:
lst.append(lst[-1] + lst[-2]) for x in range(4)
return lst
Any help is greatly appreciated.
-KF