Fibonacci September 7, 2019 Fibonacci series

class Fib:
     DEF  the __init__ (Self): 
        self.a =. 1 # define two revealed values 
        self.b, =. 1 DEF the __iter__ (Self): # Set iterator protocol return Self DEF __next__ (Self):
         IF self.a> 100 :
             The raise the StopIteration 
        self.a, self.b, = self.b,, self.a + self.b, # implemented the Fibonacci columns # A, B = B, A rapid exchange # 2 values return self.a 
F1 = Fib ()
 Print (the Next (f1))
 Print (the Next (f1))
 Print

     
        

     
        
        
(next (f1))
 Print (next (f1))
 Print ( " ++++++++++++++++++++++ " )
 for i in f1: # attention next is not walking back 
    Print (i)

》》》》

1
2
3
5
++++++++++++++++++++++
8
13
21
34
55
89
144

Guess you like

Origin www.cnblogs.com/python1988/p/11483058.html