资源简介 (共35张PPT)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.5clear清 空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 turtlet = turtle.Turtle()t.forward(100)import turtlet = turtle.Turtle()t.forward(100)t.clear() #清空画笔绘制的内容被清空。清空画笔反思总结项目代码(一)项目代码(二)项目代码(三)项目代码(四) 展开更多...... 收起↑ 资源预览