bigbigli_大大李

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):

![]()
posted @ 2020-09-22 19:56  bigbigli  阅读(1727)  评论(0编辑  收藏  举报