[ create a new paste ] login | about

Link: http://codepad.org/2b5HXtsN    [ raw code | output | fork ]

Python, pasted on Mar 13:
1
2
3
4
5
6
7
8
9
10
def fib(max):
    '''iterator that yields numbers in the Fibonacci sequence'''
    a = 0
    b = 1
    yield a
    while b <= max:
        yield b
        a, b = b, a + b

print list(fib(50))


Output:
1
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]


Create a new paste based on this one


Comments: