按索引遍历列表

2024-09-28 01:25:11 发布

您现在位置:Python中文网/ 问答频道 /正文

对于一个实验,我想创建多个矩形,其中一个是目标矩形。 因此我创建了一个x,y坐标的列表

xy_list = xy_circle(8, 200)
random.shuffle(xy_list)

以及rarget矩形的代码,x,y坐标xy\u列表[0]

target_rectangle = visual.Rect(win=mywin4, width=45, height=90, pos(xy_list[0]), lineColor='white', fillColor='blue', ori=orientations_list[1])
target_rectangle.draw()

为了节省一些时间和空间,我想使用xy-U列表的索引1-7为干扰物矩形创建一个for循环。但是我对Python还不熟悉,所以我不知道该怎么做。谁能给我个提示吗?非常感谢。你知道吗

for x, y in xy_list: 
    distractor_rectangle = visual.Rect(win=mywin4, width=45, height=90, pos=(x, y), fillColor='white')
    distractor_rectangle.draw()

Tags: posrecttarget列表widthwinlistwhite

热门问题