如何将多个圈子代码放在一个函数中?或循环?

How to put multiple circles code in one function? or loop?

from turtle import *

circle(60)

第一圈

penup()
setposition(-120, -40)
pendown()
circle(50)

第二圈

penup()
setposition(140, 0)
pendown()
circle(60)

第三圈

penup()
setposition(260, -40)
pendown()
circle(50)

最后一圈

我只是想知道如何在函数中放置 4 个圆圈。

根据您的 "or loop" 选项,这里有一个简单的方法,它可以成为一个函数,基于@MadPhysicist 的评论,该评论在@OTTTO 删除他的回答时丢失了:

Iterate over a sequence of three element tuples instead : coords = [(60, 0, 0), (...), ...]; for r, x, y in coords: – Mad Physicist

数据结构我已经做了[((x, y), radius), (...), ...]但是思路基本一样:

from turtle import Turtle, Screen

screen = Screen()

turtle = Turtle("turtle")

CIRCLES = [
    ((0, 0), 60), # first circle
    ((-120, -40), 50), # second circle
    ((140, 0), 60), # third circle
    ((260, -40), 50), # last circle
]

for position, radius in CIRCLES:
    turtle.penup()
    turtle.setposition(position)
    turtle.pendown()
    turtle.circle(radius)

turtle.hideturtle()

screen.exitonclick()
from turtle import *

circle(50)
penup()
setposition(0, 0)
pendown()

penup()
setposition(100, 0)
pendown()
circle(70)

penup()
setposition(200, 0)
pendown()
circle(90)