2013-04-08 42 views
0

我需要知道如何修復此代碼,以便當名爲「redlist」的列表被稱爲具有座標列表的列表時,它在移動函數被調用時填充這些點。這是我到目前爲止有:如何使用Python從列表中填充海龜座標?

redlist=[] 
def move(): 
     penup() 
     if color()[0]=="red":      
     #coordinates of redlist should be filled here    

def paint(): 
     pendown() 
     if color()[0]=="red": 
       begin_fill 
       redlist.append(pos()) 

回答

0

我不知道什麼座標你的意思,但我打電話給他們xy

redlist=[] 
def move(): 
     penup() 
     if color()[0]=="red":      
      x = 1 # replace this line 
      y = 2 # replace this line 
      redlist.append((x, y)) # you can access them by #x, y = redlist[-1] 
     #coordinates of redlist should be filled here    

def paint(): 
     pendown() 
     if color()[0]=="red": 
       begin_fill 
       redlist.append(pos())