A function that returns a list of the numbers of the Fibonacci series : Return List « List « Python






A function that returns a list of the numbers of the Fibonacci series

A function that returns a list of the numbers of the Fibonacci series

def fib2(n): # return Fibonacci series up to n
     """Return a list containing the Fibonacci series up to n."""
     result = []
     a, b = 0, 1
     while b < n:
         result.append(b)    # see below
         a, b = b, a+b
     return result
 
f100 = fib2(100)    # call it
print f100          # write the result


           
       








Related examples in the same category