2022年 11月 16日

python 小海龟 教案_Python少儿编程全集(一):一只小海龟(turtle库的使用)

这是Python少儿编程全集系列课程第一课,一只小海龟(tutle库的使用)

视频如下:

课程内容如下:

1.召唤小海龟,导入turtle及设置海龟图形

import turtle

turtle.shape(“turtle”)

2.设置背景颜色为蓝色

turtle.bgcolor(“blue”)

3.让小海龟向前出发,移动距离为150px

turtle.forward(150)

4.让小海龟右转,右转角度为90°

turtle.right(90)

5.经过几轮直行与右转的组合,最终形成正方形,最后再将正方形上色

turtle.fillcolor(“yellow”)

turtle.begin_fill()

结束turtle.end_fill()

6.完整代码如下:

import turtle

turtle.shape(“turtle”)turtle.bgcolor(“blue”)

turtle.fillcolor(“yellow”)

turtle.begin_fill()#移动距离为150px

turtle.forward(150)

#右转角度为90°

turtle.right(90)

#移动距离为150px

turtle.forward(150)

#右转角度为90°

turtle.right(90)

#移动距离为150px

turtle.forward(150)

#右转角度为90°

turtle.right(90)

#移动距离为150px!

turtle.forward(150)

turtle.end_fill()

留个作业(完成的回帖哦0.0):

fbdb1129ffc5b0f7de993ecf4e840678.png

![]()