数码管打印

运用数码管打印当前日期和时间

#七段电子数码管绘制
#导入库模块
from turtle import *
from random import *
#绘制单段间隔
def drawGap():
    penup()
    fd(5)
#绘制单段数码管
def drawLine(draw):
    drawGap()
    if draw:
        pendown()#画笔设置为工作模式
    else:
        penup()
    fd(20)#画笔前进20
    drawGap()
    right(90)#向右旋转90度
#根据数字绘制七段数码管
def drawDigit(digit):
    #第一段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False)
    #第二段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,1,3,4,5,6,7,8,9] else drawLine(False)
    #第三段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,2,3,5,6,8,9] else drawLine(False)
    #第四段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,2,6,8] else drawLine(False)
    left(90)
    #第五段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,4,5,6,8,9] else drawLine(False)
    #第六段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,2,3,5,6,7,8,9] else drawLine(False)
    #第七段
    pencolor(random(),random(),random())#借用随机库
    drawLine(True) if digit in [0,1,2,3,4,7,8,9] else drawLine(False)
    left(180)
    penup()
    fd(20)
   
#获得想要的数字
def drawDate(date):
        for i in date:
            drawDight(eval(i))
#主函数
def main():
    setup(800,350,200,20)
    penup()
    fd(-1500)
    pensize(5)
    drawDate("20231031")
    hideturtle
    done()
#调用函数
import datetime
current_date = datetime.datetime.now().date()
print('当前日期:',current_date)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值