7段数码管绘制
作者:互联网
import turtle as t
import time
def drawgap():
t.pu()
t.fd(5)
def drawline(draw):
t.pendown() if draw else t.penup()
t.fd(40)
drawgap()
t.right(90)
def drawdigit(digit):
drawline(True) if digit in [2,3,4,5,6,8,9] else drawline(False)
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)
t.left(90)
drawline(True) if digit in [0,4,5,6,8,9] else drawline(False)
drawline(True) if digit in [0,2,3,5,6,7,8,9] else drawline(False)
drawline(True) if digit in [0,1,2,3,4,7,8,9] else drawline(False)
t.left(180)
t.pu()
t.fd(20)
def drawdate(date):
t.pencolor("green")
for i in date:
if i == '年':
t.write('年',font = ("Arial",18,"normal"))
t.pencolor("blue")
t.fd(40)
elif i == "月":
t.write('月',font = ("Arial",18,"normal"))
t.pencolor("yellow")
t.fd(40)
elif i == "日":
t.write('日',font = ("Arial",18,"normal"))
t.pencolor("red")
else:
drawdigit(eval(i))#通过eval()将数字变成整数
def main(date):
t.setup(1500,650,20,20)
t.pu()
t.fd(-600)
t.pensize(5)
drawdate(time.strftime("%Y年%m月%d日",time.gmtime()))
t.fd(40)
t.color("red")
drawdate(date)
t.hideturtle()
t.done()
main(input("请输入一个年月日,例:2021年01月22日:\n"))
学号:3039
标签:digit,False,drawline,绘制,else,数码管,fd,True 来源: https://www.cnblogs.com/Karry0921/p/15449956.html