I am doing the python code challenges for control flow, and i came to a part of the challenges that relates to lists…th exercise says you can use a loop or 3 lines… i tried to do it with a loop and when i click on “RUN”, i get the expected result…but when i click on “Check answer” i get something that doesn’t make sense to me:
#Write your function here def append_sum(lst): for last2 in lst: lst.append(lst[-1] + lst[-2]) if len(lst) == 6: return lst #Uncomment the line below when your function is done print(append_sum([1, 1, 2]))
The result is:
[1, 1, 2, 3, 5, 8]
which as per the instructions…is the expected result…but? what’s going on here then?