小学课后服务 Python少儿编程 提高篇:10-自制钟表2 课件 (38张PPT)

资源下载
  1. 二一教育资源

小学课后服务 Python少儿编程 提高篇:10-自制钟表2 课件 (38张PPT)

资源简介

(共38张PPT)
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.
少儿编程课
时钟(二)
time模块
当地时间
将时间转化为字符串
strftime()
localtime()
time
后退指令
back()
隐藏画笔
ht()
绘制刻度表
t.ht()
……
for x in range(12):
t.forward(70)
t.down()
t.forward(30)
t.up()
t.back(100)
t.right(30)
tt = strftime('%I:%M:%S', localtime())
标准时间字符串
hour
(小时)
minute
(分钟)
second(秒)
变量
print(tt)
运行结果:
minute
分 钟
second

show
显 示
hour
小 时
本节目标(静态)
split指令获取列表
a = 'a1b1c1d1e'
b = a.split('1')
print(b)
split('分隔符'):拆分字符串。通过指定分隔符对字符串进行切片,并返回分割后的字符串列表。
运行结果:
['a', 'b', 'c', 'd', 'e']
从字符串里提取单个元素
字符串
tt = strftime('%I:%M:%S', localtime())
print(tt)
运行结果:
“04:45:30”
获取列表
tt = strftime('%I:%M:%S', localtime())
ts = tt.split(':')
列表“ts”的输出结果:
['04', '45', '30']
从列表中提取元素
s = int(ts[2]) #秒
m = int(ts[1]) #分
h = int(ts[0]) #时
利用下标定位到列表中的单个字符串,再将字符串转换为数字赋值给变量。
修改代码
tt = strftime('%I:%M:%S', localtime())
t1.write(tt)
tt = strftime('%I:%M:%S', localtime())
ts = tt.split(':')
h = int(ts[0])
m = int(ts[1])
s = int(ts[2])
获取当前时、分、秒数值
反思总结
让指针指向当前时间
重设画笔
让t1画笔回到圆心。
t1 = turtle.Turtle()
t1.ht()
t1.speed(0)
t1.up()
t1.goto(-20, -5)
t1.down()
t1 = turtle.Turtle()
t1.ht()
t1.speed(0)
seth指令
seth (或setheading):画笔的起始方向。
(90)
(0)
(-90)
(180)或(-180)
为画笔添加seth指令
t1 = turtle.Turtle()
t1.ht ()
t1.speed(0)
t1.seth (90)
画笔方向
秒针位置公式
秒针转过的角度:s * 6
06:00:00
06:00:15
06:00:30
06:00:45
让秒针指向当前时间
t1.up()
t1.right(s * 6)
t1.fd(60)
st方法
st ():显示画图时的箭头。
t = turtle.Turtle()
t.ht ()
t.st()
添加st方法
t1.up()
t1.right(s * 6)
t1.fd(60)
t1.st()
让秒针指向当前时间
让指针指向当前时间
创建画笔
t2 = turtle.Turtle()
t2.ht()
t2.speed(0)
t2.seth (90)
t2.width(2) #设置分针的画笔宽度为2
分针位置公式
分针转过的角度:m * 6
06:00:00
06:15:00
06:30:00
06:45:00
让分针指向当前时间
t2.right(m * 6)
t2.fd(50)
让分针指向当前时间
让指针指向当前时间
创建画笔
t3 = turtle.Turtle()
t3.ht()
t3.speed(0)
t3.seth (90)
t3.width(3) #设置时针的画笔宽度为3
时针整小时的位置公式
整小时情况下,时针转过的角度:h * 30
00:00:00
03:00:00
06:00:00
09:00:00
超出整小时部分的位置公式
超出整小时部分的角度:m * 0.5
00:00:00
00:15:00
00:30:00
00:45:00
时针的位置公式
h * 30 + m * 0.5
时针的位置公式:
让时针指向当前时间
t3.right(h * 30 + m * 0.5)
t3.forward(30)
让时针指向当前时间
反思总结

展开更多......

收起↑

资源预览