Isidoros Tsalalatis
Isidoros Tsalalatis

Reputation: 31

How to fix "TypeError unsupported operand type(s) for /: 'int' and 'function'"?

I keep getting below error and I don't know why index becoming function type and when I run the code and return integer.

Exception has occurred: exceptions.TypeError unsupported operand type(s) for /: 'int' and 'function'

Here is my code:

def Zero(*eq):
    if len(eq) == 0:
        index = 0
        return index
    else:
        index = eq[0][0]
        k = eq[0][1]
        if k == "+":
            res = index + 0
        elif k == "-":
            res = index - 0
        elif k == "x":
            res = index * 0
        elif k == "/":
            res = 0 / index
        else:
            if index != 0:
                res = 0 // index
        if index == 0:
            error = "Division with zero is invalid"
            return error
        else:
            return res    

def Eight(*eq):
    if len(eq) == 0:
        index = 8
        return index
    else:
        index = eq[0][0]
        k = eq[0][1]
        if k == "+":
            res = index + 8
        elif k == "-":
            res = index - 8
        elif k == "x":
            res = index * 8
        elif k == "/" and index != 0:
            res = 8 / index
        else:
            if index != 0:
                res = 8 // index
        if index == 0:
            error = "Division with zero is invalid"
            return error
        else:
            return res    

def Divide(num):
    k = '/'
    return (num, k)

And this is my execution code:

x = Zero(Divide(Eight))
print(x)

Upvotes: 0

Views: 1060

Answers (1)

blhsing
blhsing

Reputation: 106618

You should call the function Eight by putting parentheses after the function object; otherwise the function object itself is passed as an argument to Divide:

x = Zero(Divide(Eight()))

Upvotes: 1

Related Questions