-2

randomCrosses当它们在函数中一起使用时,我无法将函数的返回值 (a,b,c,d)输入到平均函数中randomAverage。有人请告诉我我错过了什么!

def randomCrosses():
    """Draws four random crosses of randomized values between 0-400 and returns the four random values a,b,c,d""" 
    a = r.randint(0,400)
    drawCross("Darkgreen",(a, 10))
    b = r.randint(0,400)
    drawCross("blue",(b, 10))
    c = r.randint(0,400)
    drawCross("magenta",(c, 10))
    d = r.randint(0,400)
    drawCross("limegreen",(d, 10))
    return(a,b,c,d)


def average(a,b,c,d):
    """Calculates and returns the average of four values a,b,c,d"""
    mean = (a+b+c+d)/4
    return mean


def randomAverage():
    """Randomizes four values 0-400 for a,b,c,d and then calculates the average of these values""" 
    a,b,c,d = randomCrosses()
    average(a,b,c,d)
4

1 回答 1

0

您缺少以下返回语句randomAverage

def randomAverage():
    """Randomizes four values 0-400 for a,b,c,d and then calculates the average of these values""" 
    a,b,c,d = randomCrosses()
    return average(a,b,c,d)
    #  ^-- you need this

现在,当你调用averageinside时randomAverage,函数 ( average) 工作正常并返回它应该返回的内容。但是,您的代码停在那里。randomAverage如果内部没有返回返回内容的返回语句,则返回average的值将average被简单地忽略。

于 2013-10-14T20:59:11.377 回答