Advertisement
FranzVuttke

fibonacci,py

Mar 10th, 2024
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | Source Code | 0 0
  1.  
  2. import sys
  3. def fib(max):
  4.     a = 0
  5.     b = 1
  6.     while a < max:
  7.         print(a, end=" ")
  8.         a, b = b, a+b
  9.     print()
  10.  
  11.  
  12. #
  13. #  generating Fibonacci series using recursion
  14. #  gen. function enclosed by external function
  15. #
  16. def fibre(max) -> list:
  17.  
  18.     lst = []
  19.     def genfib(prev:int, act:int, n:int, l:list) -> list:
  20.         if prev < n:
  21.             l.append(prev)
  22.             genfib(act, prev+act, n, l)
  23.         return l
  24.  
  25.     return genfib(0,1, max,lst)
  26.  
  27. def fiboyield(N):
  28.     a, b = 0, 1
  29.     while a <= N:
  30.         yield a
  31.         a, b = b, a + b
  32.     ...
  33.  
  34.  
  35. def main(args):
  36.     N = 108
  37.     if len(args) > 1:
  38.         N = int(args[1])
  39.     for n in (fiboyield(N)):
  40.         print(n, end=", ")
  41.     print()
  42.  
  43.  
  44. if __name__ == "__main__":
  45.     sys.exit(main(sys.argv))
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement