0

What's wrong with my fibonacci code?

num = int(input()) def fibonacci(n): #complete the recursive function if n<=1: return 1 #exit condition else: return fibonacci(n-1) + fibonacci(n-2) for number in range(num): print(fibonacci(num)) It is printing the sum of all of the numbers in the sequence when the Python Core lesson wants all of the numbers for given input printed.

11th Apr 2022, 10:04 PM
Dan
Dan - avatar
2 odpowiedzi
+ 2
for number in range(num): print(fibonacci(number))
11th Apr 2022, 10:16 PM
rodwynnejones
rodwynnejones - avatar
0
Thanks Rodwynnejones, I see I was printing the wrong thing. I needed to add a couple lines also. Here's what worked: num = int(input()) def fibonacci(n): #complete the recursive function if n == 0: return 0 elif n == 1 or n == 2: return 1 else: return fibonacci(n-1) + fibonacci(n-2) for number in range(num): print(fibonacci(number))
11th Apr 2022, 10:30 PM
Dan
Dan - avatar