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))
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
+ 1
You need to call the fib() to get output
0
It is giving recursion error. SAys max depth exceed in comparison.
0
Line 4,line7, line14 shows recursion Error