2016-11-08 44 views
0
def interval(a,b,n): 
    dx = float(b-a)/(n+1) 
    cnt = 1 
    points = [a] 
    xj = a 
    while cnt <= n+1: 
     xj += dx 
     points.append(xj) 
     cnt+=1 
    return points 
+0

爲什麼你需要它作爲一個列表理解? – wwii

+0

,因爲列表理解比循環操作簡單和短。 – user59220

+1

是什麼問題?請嘗試。 – wwii

回答

0

更換你的函數如下給出: -

def interval(a,b,n): 
    dx = float(b-a)/(n+1) 
    points = [a] 
    xj = a 
    points.extend([xj + (i * dx) for i in xrange(1, n+2)]) 
    return points