今天是Andy学Python的第11天哦!
大家好,我是Andy。
01.
基本动作
看教程,很容易理解,单词认识基本就知道函数作用了,顺序结构依次执行。
import turtle #导入turtle模块
turtle.showturtle() #显示箭头
turtle.write("天天向上") #写字符串
turtle.forward(300) #前进300像素
turtle.color("red") #画笔颜色为red
turtle.left(90) #箭头左转90度
turtle.goto(0,50) #去坐标(0,50)
turtle.goto(0,0)
turtle.penup() #抬笔,路径不画线
turtle.goto(0,300)
turtle.pendown() #落笔,路径画线
turtle.circle(100) #画圆,半径100像素
02.
画个红色正方形
import turtle
turtle.color("red")
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.left(90)
turtle.forward(100)
turtle.done()
03.
简略写法
每次都需要“库名.函数名”,太麻烦了,想起之前总结的模块导入通配符*,改写如下:
from turtle import * # from+库名+import+函数名
shape("turtle") #小海龟现形
fd(100)
left(90)
fd(100)
left(90)
fd(100)
left(90)
fd(100)
left(90)
04.
还能再简略吗
简略写法中前进100,左转90,一共写了4遍,能否考虑循环?
查阅资料后,简写如下:
from turtle import * # from+库名+import+函数名
shape("turtle") # 小海龟现形,本行可不要,主要是好玩,箭头变成了小海龟
pencolor("red")
for x in range(4): #for循环,重复4次
fd(100) #向前100
left(90) #左转90
作业
1.画一个各边不同颜色的正方形。
2.画一个奥运五环。
3.画一个红桃心。
End
不会Python,将成为人工智能时代的新“文盲”!
欢迎加入零基础自学Python计划,未来100天,Andy会把自学Python学习笔记持续输出公众号、视频号,不定期更新,邀您观战、加油、评论,亦或围观Andy被打脸。
人到中年,你一定要努力,但千万别着急。
我是Andy,一个终身学习者。