aboutsummaryrefslogtreecommitdiff
path: root/doc/fibo.py
blob: 83b8e83106dc4d5d7f88009719e79ea4b4eff888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Fibonacci numbers demo

def fib(n):    # write Fibonacci series up to n
    a, b = 0, 1
    while b <= n:
          print b,
          a, b = b, a+b

def fib2(n): # return Fibonacci series up to n
    ret = []
    a, b = 0, 1
    while b <= n:
          ret.append(b)
          a, b = b, a+b
    return ret