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