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))
5 Réponses
0
Fibonacci numbers - elements of the numerical sequence 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377
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
0
does recursion apply here?
0
It's recursive, it will count downwards and then sum upwards. Look up how recursion works and it will make sense.
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