I was able to solve the problem by manually repeating the code three times. But I wanted to do the bonus part that challenges me to use a loop. So frustrating that I cannot. This is what I came up with but it didn’t work because I was stuck in an infinite (?) spinning loop thing …
index = 0
while index <= 3:
def append_sum(lst):
lst.append(lst[-1] + lst[-2])
return lst
index += 1
Someone please explain what is wrong here and what the correct loop code is. Thank you.
Also, can someone teach me what to do so that my indents show up when I post here?
Unfortunately this is not correct because my good code lst.append(lst[-1] + lst[-2]) only runs once. Why? With my while loop tracker, I’ve written the code so that it should run three times!
YAYYYYY!! Also, I changed my while loop tracker to <=2 so that the code runs three times (tracker = 0, tracker = 1, and tracker = 2) instead of four times.
YAAYYYY!!!
For my own notes, I notice that I still need a lot of practice on loops and on global/local placement.