Fibonacci series | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 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.

19th Dec 2020, 10:37 AM
Veena Vikas
Veena Vikas - avatar
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)
19th Dec 2020, 10:58 AM
Bryan Moreno
Bryan Moreno - avatar
+ 1
Thank you but the same code is executed in python IDLE
19th Dec 2020, 12:35 PM
Veena Vikas
Veena Vikas - avatar
21st Dec 2020, 2:27 PM
Satyajeet Patra
Satyajeet Patra - avatar