Advertisement
Paarzivall

Untitled

Mar 28th, 2019
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.53 KB | None | 0 0
  1. from math import sqrt
  2.  
  3.  
  4. class Fibonacci(object):
  5.  
  6.     def __iter__(self):
  7.         self.licznik = 0
  8.         return self
  9.  
  10.     def __next__(self):
  11.         n = self.licznik
  12.         self.licznik += 1
  13.         return ((1 + sqrt(5)) ** n - (1 - sqrt(5)) ** n) / (2 ** n * sqrt(5))
  14.  
  15.  
  16. def menu():
  17.     ile = int(input("Podaj do którego wyrazu chcesz wypisać ciąg Fibonacciego:\t"))
  18.     fibonacci = Fibonacci()
  19.     myiter = iter(fibonacci)
  20.     for i in range(ile):
  21.         print(int(next(myiter)))
  22.  
  23.  
  24. if __name__ == '__main__': menu()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement