import turtle
def duan():
    turtle.penup()
    turtle.fd(5)
def zou(draw,fd):
    turtle.pendown() if draw else turtle.penup()
    turtle.fd(fd)
def drawLine(draw):   #绘制单段数码管
    duan()
    zou(draw,30)
    duan()
    turtle.right(90)
def drawLine1(draw):  # 绘制单段数码管1
    duan()
    zou(draw,10)
    duan()
def drawtdown1(draw):  # 斜线
    duan()
    zou(draw,34.7)
    duan()
def drawDigit(digit): 
    #右右下左上上右下下斜(左上)斜(左上)右(一半)下下左(一半)斜(右上)斜(右上)
    # 第1笔
    drawLine1(True) if digit in [2, 4, 5, 6, 8, 9, 'A', 'E', 'F', 'H',  'K', 'P', 'R', 'S'] else drawLine1(False)
    # 第2笔
    drawLine1(True) if digit in [2, 3, 4, 5, 6, 8, 9,'F', 'A','B','G','H','P','R','S'] else drawLine1(False)
    # 第3笔
    turtle.right(90)
    drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9, 'A', 'B', 'D', 'G', 'H', 'J', 'M', 'N' , 'O', 'Q', 'S', 'U', 'W'] else drawLine(False)
    # 第4笔
    drawLine(True) if digit in ['L',0, 2, 3, 5, 6, 8, 9, 'B', 'C', 'D', 'E', 'G', 'I', 'U','J', 'O', 'Q', 'S', 'Z'] else drawLine(False)
    # 第5笔
    drawLine(True) if digit in ['L',0, 2, 6, 8, 'A', 'C' , 'E' , 'F' , 'G', 'H' , 'J' , 'K' , 'L' , 'M' , 'N' ,'O' , 'P' , 'Q' ,'R' , 'U' , 'V' , 'W'] else drawLine(False)
    # 第6笔(因为会右转,这里调节第五笔为向上直线)
    turtle.left(90)
    drawLine(True) if digit in ['L',0, 4, 5, 6, 8, 9, 'A','C','E','F','G','H','K','M','N','O','P','Q','R','S','U','V','W'] else drawLine(False)
    # 第7笔
    drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9, 'A','B','C','D','E','F','G','O','P','Q','R','I','S','T','Z'] else drawLine(False)
    # 第8笔
    drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9, 'A','B','D','H','J','M','N','O','P','Q','R','U','W'] else drawLine(False)
    # 第9笔
    turtle.left(90)
    turtle.penup()
    turtle.fd(40)
    turtle.right(90 + 63.4)
    drawtdown1(True) if digit in ['K','N','Q','K','N','Q','R','W','X'] else drawtdown1(False)
    # 第10笔
    drawtdown1(True) if digit in ['M','N','X','Y'] else drawtdown1(False)
    # 第11笔
    turtle.right(90 + 26.6)
    turtle.penup()
    turtle.fd(20)
    turtle.right(90)
    drawLine(True) if digit in ['B','D','I','T'] else drawLine(False)
    # 第12笔
    turtle.left(90)
    drawLine(True) if digit in ['B','D','I','T','Y'] else drawLine(False)
    # 第13笔
    turtle.penup()
    turtle.fd(20)
    turtle.right(90 + 26.6)
    drawtdown1(True) if digit in ['V','X','Z','W', 0] else drawtdown1(False)
    # 第14笔
    drawtdown1(True) if digit in ['M','V','X','Y','Z','K', 0, 1] else drawtdown1(False)
    turtle.right(90 + 63.4)
    turtle.penup()
    turtle.fd(40)
    turtle.left(90)
    turtle.fd(20)
def drawDate(date):
    turtle.pencolor("green")
    for i in date:
        if i in "1234567890":drawDigit(eval(i))
        else:drawDigit(i)
def main():
    turtle.hideturtle()
    turtle.speed(100)
    turtle.setup(2400, 350,0,0)
    turtle.penup()
    turtle.fd(-1200)
    turtle.pensize(5)
    a=(list)(input("请输入只含有0-9或者A-Z的字符串:(含有空格输出所有)"))
    if ' ' in a: a='1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    drawDate((list)(a))
    turtle.done()
main()

 

 

就是从原点(左边中间的点)绕了一圈,然后写的中间的竖,之后写的斜线。

内师大

20计科汉一

指导老师:希闰高娃

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐