课件编号13903580

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

日期:2024-06-05 科目:综合实践 类型:小学课件 查看:85次 大小:699483Byte 来源:二一课件通
预览图 1/12
小学,自制,PPT,35张,课件,钟表
  • cover
(课件网) Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Cum sociis natoque tatibus et magnis dis parturient montes, nascetur ridiculus mus. 少儿编程课 时钟(三) 画笔方向 seth () 分隔字符串并返回列表 split('分隔符') 显示画笔 st () split指令获取列表 a = 'a1b1c1d1e' b = a.split('1') print(b) split('分隔符'):拆分字符串。通过指定分隔符对字符串进行切片,并返回分割后的字符串列表。 运行结果: ['a', 'b', 'c', 'd', 'e'] seth指令 seth (或setheading):画笔的起始方向。 (90) (0) (-90) (180)或(-180) 指针位置公式 秒针:s * 6 分针:m * 6 时针:h * 30 + m * 0.5 clear 清 空 if 如 果 sleep 休 眠 true 真 本节目标 秒针的运动规律 秒针当前位置 秒针消失 秒针出现在下一位置 经过一秒 …… 一直循环 sleep指令 sleep(秒数):让程序休眠(停止工作)一定秒数。 for x in range(5): print(strftime("%I:%M:%S", localtime())) for x in range(5): sleep(1) #让循环间隔一秒再进行 print(strftime("%I:%M:%S", localtime())) 运行结果: 运行结果: 休眠工具 from time import localtime,strftime,sleep 休眠 t1.up() t1.right(s * 6) t1.fd(60) t1.st() 改写代码 以显示当前秒针位置的代码为基础,在程序后面添加休眠和隐藏显示画笔命令,并建立循环。 秒针的循环代码 秒针显示当前位置 休眠一秒 隐藏秒针 进入下一秒 while True: tt = strftime('%I:%M:%S', localtime()) ts = tt.split(':') s = int(ts[2]) #获取秒    t1.seth (90)    t1.up()    t1.goto(0, 0) #画笔返回圆心位置    t1.right(s * 6)    t1.fd(60)    t1.st () #显示画笔    sleep(1) #等待一秒    t1.ht () #隐藏画笔 秒针运动 反思总结 分针的运动规律 当秒针运动到零点,分针开始运动。 while True: tt = strftime('%I:%M:%S', localtime()) ts = tt.split(':') s = int(ts[2]) t1.seth(90) t1.up() t1.goto(0,0) t1.right(s * 6) t1.fd(60) t1.st() 对循环进行分析 在while循环中,由于sleep方法的存在,每循环一次,时间会发生变化。 当“s=0”时,重新绘制分针。 while True: tt = strftime('%I:%M:%S', localtime()) ts = tt.split(':') m = int(ts[1]) s = int(ts[2]) t1.seth(90) t1.up() t1.goto(0,0) t1.right(s * 6) t1.fd(60) t1.st() 获取分钟的数值 获取每一次循环中分钟的数值 绘制分针 根据当前“m”数值绘制分针 while True: …… if s == 0: t2.seth (90) t2.up() t2.goto(0,0) t2.right(m * 6) t2.down() t2.fd(50) sleep(1) 让分针运动 时针的运动规律 同分针一样,当秒针运动到零点,重新绘制时针。 获取小时的数值 while True: tt = strftime('%I:%M:%S', localtime()) ts = tt.split(':') h = int(ts[0]) m = int(ts[1]) s = int(ts[2]) t1.seth(90) t1.up() t1.goto(0,0) t1.right(s * 6) t1.fd(60) t1.st() 获取每一次循环中小时的数值 绘制时针 根据当前“m”和“h”的数值绘制时针 if s == 0 : …… t3.seth (90) t3.up() t3.goto(0,0) t3.right(h* 30 + m * 6) t3.down() t3.fd(50) sleep(1) 让时针运动 重复绘制 绘制分针时,前一个分针没有消失。 clear指令 clear():清空当前画笔绘制的内容。 import turtle t = turtle.Turtle() t.forward(100) import turtle t = turtle.Turtle() t.forward(100) t.clear() #清空 画笔绘制的内容被清空。 清空画笔 反思总结 项目代码(一) 项目代码(二) 项目代码(三) 项目代码(四) ... ...

~~ 您好,已阅读到文档的结尾了 ~~