#drawsevensegdisplay.pyImportTurtle, DateTimedefDrawLine (Draw):#draw a single-segment digital tubeTurtle.pendown ()ifDrawElseTurtle.penup () turtle.fd (40) Turtle.right (90) defDrawdigit (digit):#Draw seven-segment digital tube based on digitalDrawLine (True)ifDigitinch[2,3,4,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDigitinch[0,1,3,4,5,6,7,8,9]ElsedrawLine (False) drawLine (True)ifDigitinch[0,2,3,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDigitinch[0,2,6,8]ElsedrawLine (False) turtle.left (90) DrawLine (True)ifDigitinch[0,4,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDigitinch[0,2,3,5,6,7,8,9]ElsedrawLine (False) drawLine (True)ifDigitinch[0,1,2,3,4,7,8,9]ElsedrawLine (False) turtle.left (180) Turtle.penup () turtle.fd (20) defDrawdate (date):#get the number to output forIinchDate:drawdigit (eval (i))#Note: Use the eval () function to turn numbers into integersdefMain (): Turtle.setup (800, 350, 200, 200) Turtle.penup () turtle.fd (-300) Turtle.pensize (5) Drawdate (Datetime.datetime.now (). Strftime ('%y%m%d')) Turtle.hideturtle () main ()
#drawsevensegdisplay.pyImportTurtle, DateTimedefDrawgap ():#Draw Digital Tube spacingTurtle.penup () turtle.fd (5) defDrawLine (Draw):#draw a single-segment digital tubeDrawgap () Turtle.pendown ( )ifDrawElseTurtle.penup () turtle.fd (40) Drawgap () Turtle.right (90) defDrawdigit (d):#Draw seven-segment digital tube based on digitalDrawLine (True)ifDinch[2,3,4,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDinch[0,1,3,4,5,6,7,8,9]ElsedrawLine (False) drawLine (True)ifDinch[0,2,3,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDinch[0,2,6,8]ElsedrawLine (False) turtle.left (90) DrawLine (True)ifDinch[0,4,5,6,8,9]ElsedrawLine (False) drawLine (True)ifDinch[0,2,3,5,6,7,8,9]ElsedrawLine (False) drawLine (True)ifDinch[0,1,2,3,4,7,8,9]ElsedrawLine (False) turtle.left (180) Turtle.penup () turtle.fd (20) defdrawdate (date): Turtle.pencolor ("Red") forIinchDate:ifi = ='-': Turtle.write ('years', Font= ("Arial", 18,"Normal")) Turtle.pencolor ("Green") TURTLE.FD (40) elifi = ='=': Turtle.write ('Month', Font= ("Arial", 18,"Normal")) Turtle.pencolor ("Blue") TURTLE.FD (40) elifi = ='+': Turtle.write ('Day', Font= ("Arial", 18,"Normal")) Else: Drawdigit (eval (i))defMain (): Turtle.setup (800, 350, 200, 200) Turtle.penup () turtle.fd (-350) Turtle.pensize (5) Drawdate (Datetime.datetime.now (). Strftime ('%y-%m=%d+')) Turtle.hideturtle () main ()
"Python" seven-segment digital display tube