8是典型的七段数码管的例子,因为刚好七段都有经过,这里我写的代码是从1开始右转。
创新互联是一家专业提供福清企业网站建设,专注与成都网站设计、网站建设、H5技术、小程序制作等业务。10年已为福清众多企业、政府机构等服务。创新互联专业网站制作公司优惠进行中。
这是看Mooc视频写的一个关于用七段数码管显示当前时间
# -*-coding:utf-8 -*-
import turtle as t
import time
def drawGap():
t.penup()
t.fd(5)
def drawLine(draw):
drawGap()
t.pendown() if draw else t.penup()
t.fd(40)
t.right(90)
def drawDigit(digit):
drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False) #当digit是2, 3, 4, 5, 6, 8, 9时执行
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.penup()
t.fd(20)
def drawDate(date):
for i in date:
if i=='-':
t.write('年',font=("Arial",18,"normal"))
t.pencolor("green")
t.fd(40)
elif i=='=':
t.write('月', font=("Arial", 18, "normal"))
t.pencolor("green")
t.fd(40)
elif i=='+':
t.write('日', font=("Arial", 18, "normal"))
t.pencolor("green")
t.fd(40)
else:
drawDigit(eval(i))
# drawDigit(eval(date))
if __name__ == '__main__':
t.setup(800,350,200,200)
t.penup()
t.fd(-300)
t.pensize(5)
drawDate(time.strftime('%Y-%m=%d+',time.gmtime())) #strftime() 函数接收以时间元组,并返回以可读字符串表示的当地时间
# drawDate('6')
t.hideturtle()
t.done()
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。