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

![]()


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM