Как вывести последовательность Фибоначчи начиная с нуля до num. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Как вывести последовательность Фибоначчи начиная с нуля до num.

Нужно вывести последовательность фибоначчи от 0 до num спомощью рекурсии Пример: num = 5 0 1 1 2 3 https://code.sololearn.com/c6Mh2XNKKbVH/?ref=app

6th Jul 2022, 8:12 AM
Александр Антонов
Александр Антонов - avatar
2 Answers
+ 4
Thanks
6th Jul 2022, 8:43 AM
Александр Антонов
Александр Антонов - avatar
+ 2
Your recursive function calculates a single element. But it starts with 1 (that is the exit condition of the recursion). If you want to start with 0, you can change it like this: if(n <= 1): return n And to print all the elements you can put your print statement in a loop: for x in range(num): print(fibonacci(x))
6th Jul 2022, 8:23 AM
Tibor Santa
Tibor Santa - avatar