Problem with list in funktions and loops | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

Problem with list in funktions and loops

Today I tried to solve the ā€œFibonacciā€ challenge in the Python course. Will doing it an error accrued I didnā€™t understood. When I tried to get an value out of an List using its index in an funktion or loop caused an error. Doing it outside on didnā€™t. That makes no sense for me, but hopefully for you. https://code.sololearn.com/cH3c2i0ud3c6/?ref=app

27th Jan 2021, 6:04 PM
Hajo Keussen
2 Respostas
+ 1
List=List.append(c) is the problem. List.append(c) adds c to List without returning anything so List.append(c) by itself is enough. Also, don't forget to decrease n unless you want infinite recursion.
27th Jan 2021, 6:27 PM
jtrh
jtrh - avatar
0
As jtrh already mentioned, append() works inplace and does not return. You can decrease n in line 12 by using (n-2) in calling the function.
27th Jan 2021, 9:33 PM
Lisa
Lisa - avatar