- 1
Fibonacci series
num = int(input()) def fibonacci(n): if n <= 1: return 0 if n == 2 or n == 3: return 1 else: return fibonacci(n-1)+fibonacci(n-2) fibonacci(num) for i in range (num): print fibonacci(i+1) What is the error in this code made in recursion model and n<=1 as base case still it is showing expected indent block or invalid syntax can anyone help.
4 Answers
+ 1
Remember that you have to indent your code properly, that's the way how python knows where your function / blocks of code start and end.
def fibonacci(n):
if n == 0:
return 0
if n == 1:
return 1
return fibonacci(n-1) + fibonacci (n-2)
+ 1
Thank you but the same code is executed in python IDLE
0
Have a look on it : )
https://code.sololearn.com/cRnPkH9bcjHg/?ref=app