+ 2
What is wrong in this code ??
def work_for_all(func): def inner(*args, **kwargs): print("I can decorate any function") return func(*args,**kwargs) return @work_for_all def div(a,b): return a/b #to run div(2,8)
1 Answer
+ 9
# Amended version
def work_for_all(func):
def inner(*args, **kwargs):
print("I can decorate any function")
return func(*args,**kwargs)
return inner
@work_for_all
def div(a,b):
return a/b
print(div(2,8))
# Basically, something had to be returned in line 7 as well as your command should actually be printing, not just doing the calculation.
# Or, you can embed the printing into the decorator function, your call.