采用turtle并使用函数封装绘制七段数码管,显示当前系统的日期和时间

采用turtle并使用函数封装绘制七段数码管,显示当前系统的日期和时间_第1张图片
代码如下:
import turtle
from turtle import *
def S(l,timelist,turtlep):
for i in range(0,l):
turtlep.setheading(0)
turtlep.penup()
turtlep.goto((60*i)-180,80)
turtlep.pendown()
if timelist[i]==0:
turtlep.right(90)
turtlep.forward(80)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(80)
turtlep.left(90)
turtlep.forward(40)
elif timelist[i]==1:
turtlep.right(90)
turtlep.forward(80)
elif timelist[i]==2:
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
elif timelist[i]==3:
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
elif timelist[i]==4:
turtlep.right(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(80)
elif timelist[i]==5:
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
elif timelist[i]==6:
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(80)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
elif timelist[i]==7:
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(80)
elif timelist[i]==8:
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.right(90)
turtlep.forward(40)
elif timelist[i]==9:
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.left(90)
turtlep.forward(40)
turtlep.right(180)
turtlep.forward(80)
turtlep.right(90)
turtlep.forward(40)
print(“这些数字”,timelist[i])
def main():
time=input(“请输入当前的日期:”)
#timelist=[int(x) for x in str(time)]
#timelist=tuple(map(int,str(time))) tuple将返回的列表属性转化成元组类型
timelist=list(map(int,str(time))) #map便利字符串转换为Int类型返回列表
l=len(timelist)
p=Turtle()
p.pensize(5)
p.speed(1)
S(l,timelist,p)
turtle.done()
main()

你可能感兴趣的:(python)