用python turtle库画一个立体的黄色五层书架
时间: 2023-07-01 14:12:38 浏览: 115
好的,以下是解决方案:
```python
import turtle
# 设置画笔颜色和填充颜色为黄色
turtle.color("yellow")
turtle.begin_fill()
# 画第一层
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第二层
turtle.up()
turtle.goto(0, 30)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第三层
turtle.up()
turtle.goto(0, 60)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第四层
turtle.up()
turtle.goto(0, 90)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 画第五层
turtle.up()
turtle.goto(0, 120)
turtle.down()
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
turtle.left(90)
turtle.forward(120)
turtle.left(90)
turtle.forward(30)
# 填充颜色
turtle.end_fill()
# 隐藏画笔
turtle.hideturtle()
# 等待用户关闭窗口
turtle.done()
```
运行以上代码,将会弹出一个窗口,显示一个立体的黄色五层书架。
阅读全文