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