generate fibonacci series in python

# WARNING: this program assumes the
# fibonacci sequence starts at 1
def fib(num):
  """return the number at index num in the fibonacci sequence"""
  if num <= 2:
    return 1
  return fib(num - 1) + fib(num - 2)


print(fib(6))  # 8

Here is what the above code is Doing:
1. If the number is less than or equal to 2, return 1.
2. Otherwise, return the sum of the previous two numbers in the sequence.

The first time we call fib(6), we get the following:

fib(6)
fib(5)
fib(4)
fib(3)
fib(2)
return 1
fib(1)
return 1
return fib(2) + fib(1)
return 1 + 1
return fib(3) + fib(2)
return fib(2) + fib(1) + 1
return 1 + 1 + 1
return fib(4) + fib(3)
return fib(3) + fib(2) + fib(2) + fib(1)
return fib(2) + fib(1) + 1 + 1 + 1
return 1 + 1 + 1 + 1 + 1

fib(6) = fib(5) + fib(4)
= fib(4) + fib(3) + fib(3) + fib(2)
= fib(3) + fib(2) + 1 + 1 + 1 + 1 + 1
= fib(2) + fib(1) + 1 + 1 + 1 + 1 + 1 + 1
= 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1
= 8