Advertisement
Guest User

Module P1

a guest
Nov 12th, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.34 KB | None | 0 0
  1. # Fibonacci numbers module
  2.  
  3. def fib(n):    # write Fibonacci series up to n
  4.     a, b = 0, 1
  5.     while a < n:
  6.         print(a, end=' ')
  7.         a, b = b, a+b
  8.     print()
  9.  
  10. def fib2(n):   # return Fibonacci series up to n
  11.     result = []
  12.     a, b = 0, 1
  13.     while a < n:
  14.         result.append(a)
  15.         a, b = b, a+b
  16.     return result
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement