0

I need explaination of the code Fibonacci series

def fib (n): if n==0: return 0 elif n==1: return 1 else: return fib(n-1)+fib(n-2) num=int(input()) for i in range(num): print(fib(i))

13th Jul 2022, 7:19 AM
Abhishek
Abhishek - avatar
5 Answers
0
Fibonacci numbers - elements of the numerical sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
13th Jul 2022, 7:25 AM
Кавун 🍉
Кавун 🍉 - avatar
0
I'm not a big expert in python, but it seems to me that numbers are being added from the end of a given number
13th Jul 2022, 7:26 AM
Кавун 🍉
Кавун 🍉 - avatar
0
does recursion apply here?
13th Jul 2022, 7:27 AM
Кавун 🍉
Кавун 🍉 - avatar
0
It's recursive, it will count downwards and then sum upwards. Look up how recursion works and it will make sense.
13th Jul 2022, 7:31 AM
Mustafa A
Mustafa A - avatar
0
This is a classical example of recursion. There are plenty of YouTube videos that explain this particular algorithm even in Python. Maybe watching some of them will help with understanding the mechanics. https://youtu.be/A3VQmxoWLHY
13th Jul 2022, 7:39 AM
Tibor Santa
Tibor Santa - avatar