2013-02-01 159 views
0

請你能幫我解決我的錯誤代碼。當我打印最後一行我得到一個語法錯誤消息:python語法錯誤輸出

import math 


m_ = 900   # identifier for normal distribution mean [mm] 
s_d = 1   # identifier for normal distribution standard deviation [mm] 

print "DISTRIBUTION OF A PLATE WIDTH:" " MEAN", "=",m_,"," "STD DEV", "=", s_d 
print "" 
print "Using functions from the math library ..." 


# The probability density function(pdf) for a normal distribution with mean m_ and 
standard deviation s_d  
ftotal = 0 
term = 0.0 
count = 0 
while abs(term) > 911: 
    ftotal += term 
    count += 1 
    term = term * xx/float(count) 


print "x" "   " " f(x)" "   " " F(x)" 
print "890" "" (1/((s_d * (2 * math.pi) ** -0.5)) * math.exp((- (x - m_) ** 2)/(2 * (s_d) ** 2), 0.5 * (1 + math.erf((x - m_)/s_d * m.sqrt(2)) 
+1

對齊while循環中的代碼。目前還不清楚你的while循環是什麼? – Hussain

+1

在最後一行的'(2 *(s_d)** 2)0.5'中的'0.5'之前還缺少運算符。 – Hussain

+0

對不起,這些是兩個分開的公式,但我不知道如何正確分開它們 –

回答

3

while循環之前定義X。從你用890表示x的最後兩行,所以我猜測x = 890

x = 890 
#your while loop goes here 

print "x" "   " " f(x)" "   " " F(x)" 
print "890" , (1/((s_d * (2 * math.pi) ** -0.5))) * math.exp((- (x - m_) ** 2)/(2 * (s_d) ** 2)) , 0.5 * (1 + math.erf((x - m_)/s_d * math.sqrt(2))) 

我不記得確切的公式,但如果上述表達式正確放置,您將不會得到語法錯誤。

+1

如果這回答你的問題,你可以通過點擊答案左側的標記來接受答案。 – Hussain