2014-02-22 49 views
0

我我定義的第一功能,工程如何使用我定義的新函數中定義的函數?

def chainPoints(aa,DIS,SEG,H): 
#xtuple 
    n=0 
    xterms = [] 
    xterm = -DIS 
    while n<=SEG: 
     xterms.append(xterm) 
     n+=1 
     xterm = -DIS + n*SEGL 
# 
#ytuple 
    k=0 
    yterms = [] 
    while k<=SEG: 
     yterm = H + aa*m.cosh(xterms[k]/aa) - aa*m.cosh(DIS/aa) 
     yterms.append(yterm) 
     k+=1 

但現在我需要依賴於我的第一個功能,speciffically名單的xterm和yterms第二功能。

def chainLength(aa,DIS,SEG,H): 
    chainPoints(aa,DIS,SEG,H) 

#length of chain 
    ff=1 
    Lterm=0. 
    totallength=0. 
    while ff<=SEG: 
     Lterm = m.sqrt((xterms[ff]-xterms[ff-1])**2 + (yterms[ff]-yterms[ff-1])**2) 
     totallength += Lterm 
     ff+=1 
return(totallength) 

我已經完成了所有沒有定義的功能,但現在我需要爲每個部分定義函數。

+1

你爲什麼只是用我的答案更新你的問題?你是說你已經這麼做了,還是你有跟進問題?如果是這樣,請不要*通過更新您的問題來使答案無效。 –

+0

對不起,有人告訴我以前更新問題。仍然是一個noob –

回答

3

您需要回從chainPoints()功能結果,然後在chainLength()功能指定的返回值本地名稱(S):

def chainPoints(aa, DIS, SEG, H): 
    #xtuple 
    n = 0 
    xterms = [] 
    xterm = -DIS 
    while n <= SEG: 
     xterms.append(xterm) 
     n += 1 
     xterm = -DIS + n * SEGL 
    # 
    #ytuple 
    k = 0 
    yterms = [] 
    while k <= SEG: 
     yterm = H + aa * m.cosh(xterms[k]/aa) - aa * m.cosh(DIS/aa) 
     yterms.append(yterm) 
     k += 1 

    return xterms, yterms 


def chainLength(aa, DIS, SEG, H): 
    xterms, yterms = chainPoints(aa, DIS, SEG, H) 

    ff = 1 
    Lterm = 0. 
    totallength = 0. 
    while ff <= SEG: 
     Lterm = m.sqrt((xterms[ff] - xterms[ff-1]) ** 2 + 
         (yterms[ff] - yterms[ff - 1]) ** 2) 
     totallength += Lterm 
     ff += 1 

    return totallength 

我用同樣的名稱在chainLength這裏,但不是要求。

+0

好吧,但我如何使用我的chainLength函數?我不知道要爲xterms和yterms參數放置什麼? –

+0

@BobUnger:我拼出來給你一些。 –