2013-10-14 61 views
-2

我不能獲得randomCrosses函數的返回值(a,b,c,d),當它們在randomAverage函數中一起使用時,會返回到平均函數中。有人請告訴我我錯過了什麼!從另一個函數計算平均值的Python函數

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) 
+0

你的實際問題是什麼?如果你運行你的代碼會發生什麼? – Michael0x2a

+1

你錯過了'randomAverage'中的return語句。 –

回答

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 

現在,當你調用averagerandomAverage,函數(average)工作正常,返回它應該。但是,您的代碼停在那裏。如果randomAverage內部沒有返回語句,返回average返回的內容,則簡單地忽略由average返回的值。

相關問題