#!/usr/bin/python
def func_decorator(func):
def wrapper(x):
if x == 0:
raise Exception('Denominator is zero ...');
return func(x);
return wrapper;
@func_decorator
def inverse(x):
return 1.0/x;
try:
print inverse(10);
print inverse(0);
except Exception, e:
print e
class Fibonacci:
def __init__(self):
self.cache = {}
def __call__(self, n):
if n not in self.cache:
if n == 0:
self.cache[0] = 0
elif n == 1:
self.cache[1] = 1
else:
self.cache[n] = self.__call__(n-1) + self.__call__(n-2)
return self.cache[n]
fib = Fibonacci()
for i in range(15):
print(fib(i), end=", ")