- 1
how to find fibonacci series using recursion
3 Respuestas
+ 5
num = int(input()) #Entrada del usuario
def fibonacci(n):
if n == 0:
return 0
elif n == 1:
return 1
else:
return fibonacci(n-1) + fibonacci(n-2)
for i in range(num):
print(fibonacci(i)) #Llamada de la funcion
0
num = int(input())
fib = [0, 1]
def fibonacci(n):
if n == 2:
[print(i) for i in fib]
else:
fib.append(sum(fib[-2:]))
fibonacci(n - 1)
fibonacci(num)