I see additional tabs in your solution, and also the logic of your program is incorrect. As I understand it, writing fib(5), you need the 5th Fibonacci in the series (5), and not a number that is less than 5 (this is 3).
a=b
b=a+b
and
a,b = b,a+b
not equal.
Take a look at the code below.
def fibonacci(num):
a,b=0,1;
counter = 2;
while(a<=):
a,b = b,a+b
counter += 1
return b
print fibonacci(5)
source
share