-1

I have written the below code using decorator and the code is returning None when I am expecting an integer or float value. the function (num(a, b)) returns a value when I don't use decorator and the issue comes when I use decorator. Can someone please clarify why the code is returning None. Below is the code:

def decor(func):
    def inner(a, b):
        if a <= b:
            print("If executed")
            a, b = b, a
            c = a - b
            print(c)
            return c
        else:
            print("else executed")
            func(a, b)
    return inner


def num(a, b):
    print("Function executed")
    d = (a - b)
    print(d)
    return d


num = decor(num)

print(num(3, 5))  # this is returning a value
print(num(3, 1))  # this is returning None
tripleee
  • 175,061
  • 34
  • 275
  • 318

1 Answers1

0

Your inner function has no return statement in the else branch. Presumably you meant to write return func(a, b)?

ndc85430
  • 1,395
  • 3
  • 11
  • 17
  • This is my first stackoverflow query and the community is so quick to help, thanks. I fixed the code now by updating else statement to return func(a,b) and it worked... – Kiran Vangari Oct 08 '22 at 08:07