如何解决“为/类型错误不支持的操作数类型(S):‘诠释’和‘功能’?”

问题描述 投票:0回答:1

我不断收到以下错误,我不知道为什么指数成为功能型,当我运行的代码,并返回整数。

异常发生:“INT”和“功能”:用于/ exceptions.TypeError不受支持的操作数类型

这里是我的代码:

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)

这是我执行代码:

x = Zero(Divide(Eight))
print(x)
python python-2.7
1个回答
1
投票

你应该把括号函数对象后调用的函数Eight;否则函数对象本身作为参数传递到Divide

x = Zero(Divide(Eight()))
© www.soinside.com 2019 - 2024. All rights reserved.