0

Good Morning Coders, Why is Code returning Empty.

n = int(input()) def fib(n): if n<=1: return n else: return fib((n-1)+fib(n-2)) if n<=0: print("please enter a positive integer") else: print("Fibonacci Sequence") for i in range(n): print(fib(i))

17th Feb 2021, 4:50 AM
We Doru
We Doru - avatar
4 Respostas
+ 6
Wedo Ru You need to remove opening ( and closing ) brackets from else part.... return fib((n - 1) + fib(n - 2)) n = int(input()) def fib(n): if n<=1: return n else: return fib(n - 1) + fib(n - 2) if n <= 0: print("please enter a positive integer") else: print("Fibonacci Sequence") for i in range(n): print(fib(i)) https://code.sololearn.com/cetTKbB07x1E/?ref=app
17th Feb 2021, 5:18 AM
A͢J
A͢J - avatar
+ 1
You need to call the fib() to get output
17th Feb 2021, 4:52 AM
Indranil
Indranil - avatar
0
It is giving recursion error. SAys max depth exceed in comparison.
17th Feb 2021, 4:56 AM
We Doru
We Doru - avatar
0
Line 4,line7, line14 shows recursion Error
17th Feb 2021, 4:57 AM
We Doru
We Doru - avatar