Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
python:一旦我的函数完成了我想要的任务,我怎么能让它停止读取列表呢_Python_List_Function - Fatal编程技术网

python:一旦我的函数完成了我想要的任务,我怎么能让它停止读取列表呢

python:一旦我的函数完成了我想要的任务,我怎么能让它停止读取列表呢,python,list,function,Python,List,Function,我需要能够使用列表中的数据将4张纸粘贴到广告牌背景上,以下是该列表的一小部分: data_sets = [ # These two initial data sets don't put any sheets on the billboard # Data sets 0 - 1 ['O'], ['X'], # These data sets put Sheet A in all possible locations and orientations # Data sets 2 - 9 ['O',

我需要能够使用列表中的数据将4张纸粘贴到广告牌背景上,以下是该列表的一小部分:

data_sets = [
# These two initial data sets don't put any sheets on the billboard
# Data sets 0 - 1
['O'],
['X'],
# These data sets put Sheet A in all possible locations and orientations
# Data sets 2 - 9
['O', ['Sheet A', 'Location 1', 'Upright']],
['O', ['Sheet A', 'Location 2', 'Upright']],
['O', ['Sheet A', 'Location 3', 'Upright']],
['O', ['Sheet A', 'Location 4', 'Upright']],
['O', ['Sheet A', 'Location 1', 'Upside down']],
['O', ['Sheet A', 'Location 2', 'Upside down']],
['O', ['Sheet A', 'Location 3', 'Upside down']],
['O', ['Sheet A', 'Location 4', 'Upside down']]
]
我试着让乌龟画我的表格,但一旦它画了,它会继续浏览整个列表并绘制轮廓,我需要它在执行sheet_a_直立()后停止浏览列表。“x”和“o”在这一点上没有任何意义,不要理会它们。同样的事情也发生在我的goto_loc()函数上,但我通过将数据集作为参数来修复它,当我对sheet()函数执行此操作时,它最终没有绘制任何东西

#location function for data_sets
def goto_loc(data_sets):
    for location in data_sets:
        if len(location)>1 and 'Location 1' in location[1]:
            goto(-300, 0)
        elif len(location)>1 and 'Location 2' in location[1]:
            goto(-100, 0)
        elif len(location)>1 and 'Location 3' in location[1]:
            goto(100, 0)
        elif len(location)>1 and 'Location 4' in location[1]:
            goto(300, 0)

#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()
        elif len(style)>1 and 'Sheet B' in style[1]:
            sheet_b_upright()
        elif len(style)>1 and 'Sheet C' in style[1]:
            sheet_c_upright()
        elif len(style)>1 and 'Sheet D' in style[1]:
            sheet_d_upright()

#define sheet outline and fill
def outline():
    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():
    #sheet outline and fill
    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)
        sheet()

paste_up(data_sets[2])

如果执行了
sheet\u a\u直立()
,请让您的
sheet
函数
返回True

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()
                elif len(style)>1 and 'Sheet C' in style[1]:
                    sheet_c_upright()
                elif len(style)>1 and 'Sheet D' in style[1]:
                    sheet_d_upright()
然后,在
粘贴
函数中,检查
sheet()
是否为真:

def paste_up(data_sets):
            for each in data_sets:
                goto_loc(data_sets)
                if sheet():
                    return

如果执行了
sheet\u a\u直立()
,请让您的
sheet
函数
返回True

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()
                elif len(style)>1 and 'Sheet C' in style[1]:
                    sheet_c_upright()
                elif len(style)>1 and 'Sheet D' in style[1]:
                    sheet_d_upright()
然后,在
粘贴
函数中,检查
sheet()
是否为真:

def paste_up(data_sets):
            for each in data_sets:
                goto_loc(data_sets)
                if sheet():
                    return