Monday, 14 August 2017

Fibonacci series

write Fibonacci series up to n

def fib(n):
    a, b = 0, 1
    while b < n:
        print(b,)
        a, b = b, a+b
fib(100)

Output:


1
1
2
3
5
8
13
21
34
55
89

No comments:

Post a Comment