from turtle import*
from random import*
绘制单段数码管:
import time
import turtle
def drawGap():
turtle.penup()
turtle.fd(5)
def drawLine(draw):#绘制单段数码管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
drawGap()
turtle.right(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)
pencolor(random (), random () , random ())