 # Problem with Fibonacci series algorithm

Hi
can you explain the logic how it is getting converted into Fibonacci series
a=1
b=1
temp=a+b
a=b
b=1
print (temp)

This won’t give you fibonacci series, this will simply print `2`.
Can you please provide complete code snippet

a=1

b=1

print (a)

print (b)

while b<1000 :

``````temp=a+b

a=b

b=temp

print (temp)``````

for the below code i am getting error: Please suggest the solution:
if(Number == 0):

``````                  return 0

elif(Number == 1):

return 1

else:

return (Fibonacci_series(Number - 2)+ Fibonacci_series(Number - 1))
``````

Number = int(input("\nPlease Enter the Range Number: "))
ERROR
File “”, line 3 elif(Number == 1): ^ IndentationError: unindent does not match any outer indentation level

For the lines, please give indentation properly. You have given two tab spaces.

Write it as :

``````if condition1:
statement1
elif condition2:
statement2
else:
statement3
``````

All the statements should be aligned as one tab space only. But you’ve given excessive indentation due to which this error is there.

Also with the right indentation,I am, getting error.Please suggest

You’ve given indentation for else if and else as well.

1 Like

please find below two codes: Code1 is working fine but having issues with code 2.what is wrong with code 2??
Also kindly suggest if I can create a single thread and post all my queries within that post,which will help me in future to get all info in a single page
Code1
n = int (input(‘Enter your number :’))

def factorial (n):

``````if (n==1):

return 1

else:

return n * factorial(n-1)
``````

print (factorial (n))
Code 2
n = int (input(‘Enter your number :’))

if (n>=0):

return n * (n-1)

print (n)

Hi @rithikalalith!! thanks for your response
i did the same. please find the screenshot of the error:

I would suggest you to take some basic programming course on either python or any other language.
Doing so will help in understanding a few basic concepts like conditional blocks, return is used to return a value or object from a function.
As a suggestion, you can refer to one of the books for python, shared in Learning Resources Master List

1 Like
``````n= int(input())
a=1
b=1
for i in range(3,n+1):
temp = a+b
a=b
b=temp
print(temp)
``````