June 9, 2015
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #!/usr/bin/env python class Fibo: "Class-based Fibonacci recursion" def __init__( self , n): if n = = 1 : self .value = 1 elif n = = 2 : self .value = 1 else : A = Fibo(n - 1 ) B = Fibo(n - 2 ) self .value = A.value + B.value def __repr__( self ): return str ( self .value) if __name__ = = "__main__" : print Fibo( 1 ) print Fibo( 2 ) print Fibo( 3 ) print Fibo( 4 ) print Fibo( 5 ) print Fibo( 6 ) print Fibo( 7 ) print Fibo( 8 ) print Fibo( 9 ) print Fibo( 10 ) |
Comments Off on Fibonacci Recursion implemented by Python class