June 9, 2015
#!/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