简体   繁体   English

如何修复“ /:'int'和'function'的TypeError不支持的操作数类型”?

[英]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' 发生异常:exceptions.TypeError不支持/的操作数类型:“ int”和“ 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)

You should call the function Eight by putting parentheses after the function object; 您应该通过在函数对象后面加上括号来调用函数Eight otherwise the function object itself is passed as an argument to Divide : 否则,函数对象本身将作为参数传递给Divide

x = Zero(Divide(Eight()))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何修复TypeError:+:'int'和'list'的不支持的操作数类型 - How to fix TypeError: unsupported operand type(s) for +: 'int' and 'list' 如何解决“ TypeError:+不支持的操作数类型:'int'和'NoneType'” - How to fix “TypeError: unsupported operand type(s) for +: 'int' and 'NoneType'” 如何修复错误 - TypeError:不支持的操作数类型 - :'tuple'和'int' - How to fix error - TypeError: unsupported operand type(s) for -: 'tuple' and 'int' 如何为+ =:'DeferredAttribute'和'int'修复TypeError不支持的操作数类型 - How to fix TypeError unsupported operand type(s) for +=: 'DeferredAttribute' and 'int' 如何修复“TypeError:不支持的操作数类型-:‘NoneType’和‘int’” - How to fix 'TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'' 如何修复 Python TypeError:不支持的操作数类型“int”和“tuple” - How to fix Python TypeError: unsupported operand type(s) 'int' and 'tuple' 如何解决,TypeError:%不支持的操作数类型:'NoneType'和'int' - How to fix, TypeError: unsupported operand type(s) for %: 'NoneType' and 'int' TypeError:*:'function'和'int'不支持的操作数类型 - TypeError: unsupported operand type(s) for *: 'function' and 'int' 类型错误:不支持 + 的操作数类型:'function' 和 'int' - TypeError: unsupported operand type(s) for +: 'function' and 'int' 如何修复类型错误:+ 的不支持的操作数类型:'function' 和 'int'? - How to fix the Type error: unsupported operand type(s) for +: 'function' and 'int'?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM