"Python" Seven digital tube date

Source: Internet
Author: User

Import Turtle #画画库
Import Time #时间库
Def drawgap (): #每个数码管距离, imaging digital tube
Turtle.penup ()
TURTLE.FD (5)
def drawLine (draw): #单个数码管
Drawgap ()
Turtle.pendown () If draw else Turtle.penup () #如果是真, down, if false on up
TURTLE.FD (40)
Drawgap ()
Turtle.right (90)
def drawdigit (digit): #根据当前数字画几段数码管
DrawLine (True) if digit in [2,3,4,5,6,8,9] else DrawLine (False) #对123456 ... Digital Tube Planning
DrawLine (True) if digit in [0,1,3,4,5,6,7,8,9] else DrawLine (False)
DrawLine (True) if digit in [0,2,3,5,6,8,9] else DrawLine (False)
DrawLine (True) if digit in [0,2,6,8] else DrawLine (False)
Turtle.left (#这里不需要右拐), so add a left turn
DrawLine (True) if digit in [4,5,6,8,9,0] else DrawLine (False)
DrawLine (True) if digit in [2,3,5,6,7,8,9,0] else DrawLine (False)
DrawLine (True) if digit in [1,2,3,4,7,8,9,0] else DrawLine (False)
Turtle.left (#方向往右)
Turtle.penup () #提笔
TURTLE.FD (#移动)
def drawdate (date): #开始画时间
Turtle.pencolor (' Red ') #先直接把画笔染成红色
For I in Date:
if i = = '-': #如果是-
Turtle.write (' Year ', font= (' Arial ', ' normal ')) #那就画年
Turtle.pencolor (' green ')
TURTLE.FD (40)
elif i = = ' = ': #如果是 =
Turtle.write (' Month ', font= (' Arial ', ' normal ')) #那就画月
Turtle.pencolor (' Blue ')
TURTLE.FD (40)
elif i = = ' + ': #如果是 +
Turtle.write (' Day ', font= (' Arial ', ' normal ')) #那就画日
Else
Drawdigit (eval (i)) #不然正常画数码管
def main ():
Turtle.setup (800,350,200,200) #画布大小
Turtle.penup ()
TURTLE.FD (-300)
Turtle.pensize (5)
Drawdate (Time.strftime ('%y-%m=%d+ ', Time.gmtime ())) #用gmtime获取当前时间, format into-=+ format, and then place it in Drawdate ()
Turtle.hideturtle ()
Turtle.done ()
Main ()
The whole process in plagiarism, too difficult!
Study hard and keep up!

"Python" Seven digital tube date

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.