python用turtle写字母G?
发布网友
发布时间:2023-12-09 13:16
我来回答
共1个回答
热心网友
时间:2024-02-15 06:34
import turtle
# 创建画布和画笔
canvas = turtle.Screen()
pen = turtle.Turtle()
# 设置画笔的属性
pen.pensize(5)
pen.color("blue")
# 绘制字母G
pen.penup()
pen.goto(-100, 100)
pen.pendown()
pen.right(90)
pen.forward(100)
pen.left(90)
pen.forward(50)
pen.left(90)
pen.forward(50)
pen.right(90)
pen.forward(50)
pen.right(90)
pen.forward(100)
pen.right(90)
pen.forward(50)
pen.right(90)
pen.forward(35)
canvas.exitonclick()
运行以上代码,将会使用turtle库绘制出字母G。画布会在点击后关闭。