- 一、主要内容
- 二、知识点
- (1)输出字符
- (2)绘制螺旋图
- (3)语句介绍
- 三、创新
- 1、输出字符
- 2、螺纹
- 3、五环
1、基础知识;2、输出字符;3、海龟绘图;
二、知识点 (1)输出字符说明:
1、进行简单的字符输出。
2、在程序中所有字符均为英文字符。
3、在程序开头中,不能随便增加空格,Python中空格具有缩进含义。
程序:
print("a")
print("b")
print("c")
结果展示:
说明:
1、python用空格缩进而不是{}表示语句块。
2、python中缩进自动设置为4个空格。
3、每个语句从新一行的首列开始。
4、行注释前加#。
5、段注释使用三个单引号‘’‘。当解释器扫描到下一个’‘’,就会认为中间的为注释。
程序:
import turtle # 导入海龟绘图
t = turtle.Pen()
for x in range(360): # 循环360次
t.forward(x) # 前进x个字符
t.left(59) # 左转59度
'''for循环内,循环内容前空四行'''
'''python新手,望多指教'''
结果展示:
说明:
1、使用时先导入海龟绘图模块;
2、会调用模块中的各个语句;
程序:
import turtle # 导入海龟绘图模块
turtle.showturtle() # 显示箭头
turtle.color("blue") # 线条颜色
turtle.forward(100) # 前进100像素
turtle.color("red") # 线条颜色
turtle.write("公众号:小小创客者") # 写字符串
turtle.color("green") # 线条颜色
turtle.left(30) # 左转三十度
turtle.forward(150) # 前进150像素
turtle.goto(100, 50) # 将箭头直接移动到x,y处
turtle.penup() # 抬笔,路经不会有线条
turtle.goto(10, 40) # 将箭头直接移动到x,y处
turtle.pendown() # 落笔
turtle.color("red")
turtle.circle(50) # 逆时针绘制半径为50的圆
turtle.done() # 绘图完成后,使图不会消失
结果展示:
输出心形字符串组合。
程序:
print(" ❤ ")
print(" ❤ ❤ ❤ ")
print(" ❤ ❤ ❤ ❤ ")
print(" ❤ ❤ ❤ ❤ ❤ ")
结果展示:
2、螺纹运用for循环进行螺纹绘制,需注意缩进、注释、字符的种类。
程序:
import turtle # 导入海龟绘图
t = turtle.Pen()
for x in range(100): # 循环100次
t.forward(x) # 前进x个字符
t.left(19) # 左转19度
'''for循环内,循环内容前空四行'''
'''python新手,望多指教'''
结果展示:
3、五环运用海龟画图绘制奥运五环。
程序:
import turtle
turtle.width(10) # 线宽
turtle.speed(1) # 调速
t = turtle
t.color("blue") # 颜色
t.penup() # 抬笔
t.goto(-104, 0) # 移动至x,y
t.pendown() # 落笔
t.circle(48) # 绘制半径为48的圆
t.color("yellow")
t.penup()
t.goto(-56, -40)
t.pendown()
t.circle(48)
t.color("black")
t.penup()
t.goto(0, 0)
t.pendown()
t.circle(48)
t.color("green")
t.penup()
t.goto(56, -40)
t.pendown()
t.circle(48)
t.color("red")
t.penup()
t.goto(104, 0)
t.pendown()
t.circle(48)
t.color("red")
t.penup()
t.goto(-20, -60)
t.pendown()
t.write("奥运五环")
t.done()
展示结果:



