pythonturtle代码题库
时间: 2023-09-15 20:22:43 浏览: 197
你好!很高兴回答您的问题。以下是一些Python Turtle的代码题库示例:
1. 绘制一个正方形:
```python
import turtle
def draw_square():
for _ in range(4):
turtle.forward(100)
turtle.right(90)
turtle.speed(1)
draw_square()
turtle.done()
```
2. 绘制一个五角星:
```python
import turtle
def draw_star():
for _ in range(5):
turtle.forward(100)
turtle.right(144)
turtle.speed(1)
draw_star()
turtle.done()
```
3. 绘制一个彩虹:
```python
import turtle
def draw_rainbow():
colors = ["red", "orange", "yellow", "green", "blue", "purple"]
turtle.width(10)
turtle.penup()
turtle.goto(-300, 0)
turtle.pendown()
for color in colors:
turtle.color(color)
turtle.circle(150)
turtle.penup()
turtle.forward(30)
turtle.pendown()
turtle.speed(1)
draw_rainbow()
turtle.done()
```
这些示例展示了如何使用Python Turtle库进行绘图。您可以根据需要进行修改和扩展。希望对您有所帮助!如果您有其他问题,请随时提问。
阅读全文