Problem with list in funktions and loops | Sololearn: Learn to code for FREE!
Новый курс! Каждый программист должен знать генеративный ИИ!
Попробуйте бесплатный урок
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 ответов
+ 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