I am trying to learn how to use decorators by using the following code but I don't know why it's showing a type error.
#WAP to calculate Q = [(2*C*D)/H]^(1/2)
c = int(input("Enter a number : "))
d = int(input("Enter a number : "))
h = int(input("Enter a number : "))
def smart(func):
def inner(h):
if h == 0:
q = "It is not possible."
return
return func
return inner(h)
@smart
def calculate(c,d,h):
q = ((2*c*d)/h)**(1/2)
print(q)
calculate(c,d,h)
OK so i have solved the issue but I still don't know why it works could someone explain.
#WAP to calculate Q = [(2*C*D)/H]^(1/2)
c = int(input("Enter a number : "))
d = int(input("Enter a number : "))
h = int(input("Enter a number : "))
def smart(func):
def inner(c,d,h):
if h == 0:
print("It is not possible.")
else:
return func(c,d,h)
return inner
@smart
def calculate(c,d,h):
q = ((2*c*d)/h)**(1/2)
print(q)
calculate(c,d,h)