1
data_sets = [
['O', ['Sheet C', 'Location 2', 'Upright'],
['Sheet B', 'Location 3', 'Upright'],
['Sheet D', 'Location 1', 'Upright'],
['Sheet A', 'Location 4', 'Upright']]
['X', ['Sheet A', 'Location 1', 'Upright'],
['Sheet B', 'Location 2', 'Upright'],
['Sheet C', 'Location 3', 'Upright'],
['Sheet D', 'Location 4', 'Upright']],
]
我需要能夠將正確的工作表粘貼到正確的位置。我當前的代碼是能去到正確的位置,但它只能貼上去sheet_a_upright(),而不是片,我想例如它的工作原理與此列表,但隨後粘貼了一個額外的表:python:我如何讓烏龜從列表中執行某些操作?
data_sets = [
['O', ['Sheet A', 'Location 1', 'Upright']]
]
代碼可以粘貼到正確的位置,但不會粘貼正確的表單。如果我將它粘貼在問題開始時我列出的前兩個列表中的一個,它將只在所有4個位置粘貼表單A. 我的代碼如下:
def goto_loc(data_sets):
for location in data_sets:
if len(location)>1 and 'Location 1' in location[1]:
goto(-300, 0)
sheet()
elif len(location)>1 and 'Location 2' in location[1]:
goto(-100, 0)
sheet()
elif len(location)>1 and 'Location 3' in location[1]:
goto(100, 0)
sheet()
elif len(location)>1 and 'Location 4' in location[1]:
goto(300, 0)
sheet()
#function for which sheet should be drawn from data_sets
def sheet():
for style in data_sets:
if len(style)>1 and 'Sheet A' in style[1]:
sheet_a_upright()
return True
elif len(style)>1 and 'Sheet B' in style[1]:
sheet_b_upright()
return True
elif len(style)>1 and 'Sheet C' in style[1]:
sheet_c_upright()
return True
elif len(style)>1 and 'Sheet D' in style[1]:
sheet_d_upright()
return True
#define sheet outline and fill
def outline():
pencolor('black')
penup()
forward(100)
pendown()
fillcolor('green')
begin_fill()
left(90)
fd(250)
left(90)
fd(200)
left(90)
fd(500)
left(90)
fd(200)
left(90)
fd(250)
right(90)
penup()
end_fill()
#function for sheet A in upright position
def sheet_a_upright():
outline()
def sheet_b_upright():
outline()
def sheet_c_upright():
outline()
def sheet_c_upright():
outline()
# Paste the sheets onto the billboard as per the provided data set
def paste_up(data_sets):
for each in data_sets:
goto_loc(data_sets)
if sheet():
return
#the number i put into data_sets[] depends on which list i want to paste
paste_up(data_sets[0])
我怎樣才能讓我的代碼到右側紙粘貼在正確的位置,然後停止在最後一次粘貼的(我diddn't包括對錶的代碼?由於其繪製時間太長且不重要,所以輪廓功能只是在該位置周圍繪製邊框)
輪廓是故意的,我diddnt包括工作表的繪圖代碼COS只是一個長期的龜指令。該問題似乎與goto_loc()和/或sheet()定義相關,代碼只能粘貼sheet_a_upright()。 –