【问题标题】:Calling functions from other functions从其他函数调用函数
【发布时间】:2018-05-17 07:26:41
【问题描述】:

在输入为TypeError: 'int' object is not callable 后,我无法让该程序正常运行所有它返回的内容

#!/usr/bin/python3



def displaymenu():

    input32=int(input("1)  Run experiment\n2) Exit"))
    return input32  
def cal1(we,woc,wa):

    wala=we*woc(wa-woc)
    return wala

def cal2(wo,woh):

    wolo=24*wo*woh*wa
    return wolo

def cal3(wa,woc):

    wele=wa**2+woc(wa-woc)
    return wele

def beamere(wala,wolo,wele):

    y=(wala/wolo)*wele
    return y

input32 = displaymenu()
while input32 is not 2:

    if input32 == 1:
        we= int(input("enter your width"))
        wo= int(input("enter what ever this is"))
        woh=int(input("enter this thing"))
        wa= int(input("i really should stop calling my varibles random sylibles"))
        woc=int(input("enter your woc"))
        wala  =  cal1(we,woc,wa)
        wolo  =  cal2(wo,woh)
        wele  =  cal3(wa,woc)
        y     =  beamere(wala,wolo,wele)
        print(y)



    elif input32 == 2:


        print("learn english")
        break
    else:
        input32 = displaymenu()

【问题讨论】:

  • woc(wa-woc) 是一个函数调用,而不是乘法。是的,你不应该使用如此糟糕的变量名,但也许可以修复它而不是将其包含在提示中。

标签: python python-3.x


【解决方案1】:

在函数def cal1中修改该行 来自

wele=wa**2+woc(wa-woc)

wele=wa**2+woc*(wa-woc)

woc(wa-woc)-> 表示对 woc 的函数调用,参数为 'wa-woc'

【讨论】:

    【解决方案2】:

    这是由于您的cal1cal3: 在执行wala=we*woc(wa-woc) 时,您是在告诉python 使用woc 作为一个函数,您可能打算使用wala=we*woc*(wa-woc)woc 乘以(wa-woc)。第二个函数也是如此。

    这是您的函数的外观:

    def cal1(we,woc,wa):
    
        wala=we*woc(wa-woc)
        return wala
    
    def cal3(wa,woc):
    
        wele=wa**2+woc(wa-woc)
        return wele
    

    【讨论】:

      猜你喜欢
      • 2021-02-26
      • 1970-01-01
      • 2013-07-20
      • 2013-01-12
      • 1970-01-01
      • 2019-09-24
      • 2016-05-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多