A function that writes the Fibonacci series to an arbitrary boundary : Function Define « Function « Python






A function that writes the Fibonacci series to an arbitrary boundary

A function that writes the Fibonacci series to an arbitrary boundary
 



def fib(n):    # write Fibonacci series up to n
     """Print a Fibonacci series up to n."""
     a, b = 0, 1
     while b < n:
         print b,
         a, b = b, a+b
 
# Now call the function we just defined:
fib(2000)

           
         
  








Related examples in the same category

1.A function definitionA function definition
2.Power functionPower function
3.Define simple function in PythonDefine simple function in Python
4.Define a function in PythonDefine a function in Python
5.Function call
6.Factorial functionFactorial function