1. Descripción del problema: use un tubo digital de siete segmentos para mostrar su cumpleaños, con el año, mes y día, y use diferentes colores para indicarlo.
import turtle, time
def drawLine (draw):
# Dibuja un tubo digital de un solo segmento drawGap () # ps: La función que hace que el intervalo entre año, mes y día ...
turtle.pendown () if draw else turtle.penup ()
turtle.fd (40)
drawGap () # ps: es la función que hace que aparezca el intervalo entre año, mes y día ...
turtle.right (90)
def drawDight (dight): # dibuja un digital de siete segmentos tube
drawLine (True) if dight in [2, 3, 4, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 3, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 6, 8] else drawLine (False)
turtle.left (90)
drawLine (True) if dight en [0, 4, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 3, 5, 6, 7, 8, 9] else drawLine (Falso)
drawLine (True) if dight en [0, 1, 2, 3, 4, 7, 8, 9] else drawLine (False)
turtle.left (180)
turtle.penup () # Determina la posición para dibujar los números posteriores
turtle. fd (20)
def drawDate (fecha): # Obtiene el número que se
generará turtle.pencolor ("rojo")
para i en fecha:
if i == '-':
turtle.write ('año', fuente = ("Arial", 18 , "Normal"))
turtle.pencolor ("verde")
turtle.fd (40)
elif i == '=':
turtle.write ('月', font = ("Arial", 18, "normal"))
turtle .pencolor (“azul”)
turtle.fd (40)
elif i == '+':
turtle.write ('日', font = (“Arial”, 18, “normal”))
else:
drawDight (eval ( i)) # Convierta caracteres y números en números y luego imprímalos en tubos digitales
def drawGap (): # intervalo
turtle.penup ()
turtle.fd (5)
def main ():
turtle.setup (800, 350, 200, 200)
turtle.penup ()
turtle.fd (-300)
turtle.pensize (5)
drawDate (time.strftime ('1997-06 = 18 +', time.gmtime ()))
turtle.hideturtle ()
turtle.done ()
main () El
resultado de ejecución es el siguiente:
2. Utilice el tubo digital de siete segmentos para generar la hora actual del sistema.
import turtle, time
def drawLine (draw):
# Dibuja un tubo digital de un solo segmento drawGap () # ps: La función que hace que el intervalo entre año, mes y día ...
turtle.pendown () if draw else turtle.penup ()
turtle.fd (40)
drawGap () # ps: es la función que hace que aparezca el intervalo entre año, mes y día ...
turtle.right (90)
def drawDight (dight): # dibuja un digital de siete segmentos tube
drawLine (True) if dight in [2, 3, 4, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 3, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 6, 8] else drawLine (False)
turtle.left (90)
drawLine (True) if dight en [0, 4, 5, 6, 8, 9] else drawLine (False)
drawLine (True) if dight en [0, 2, 3, 5, 6, 7, 8, 9] else drawLine (Falso)
drawLine (True) if dight en [0, 1, 2, 3, 4, 7, 8, 9] else drawLine (False)
turtle.left (180)
turtle.penup () # Determina la posición para dibujar los números posteriores
turtle. fd (20)
def drawDate (fecha): # Obtiene el número que se
generará turtle.pencolor ("rojo")
para i en fecha:
if i == '-':
turtle.write ('año', fuente = ("Arial", 18 , "Normal"))
turtle.pencolor ("verde")
turtle.fd (40)
elif i == '=':
turtle.write ('月', font = ("Arial", 18, "normal"))
turtle .pencolor (“azul”)
turtle.fd (40)
elif i == '+':
turtle.write ('日', font = (“Arial”, 18, “normal”))
else:
drawDight (eval ( i)) # Convierta caracteres y números en números y luego imprímalos en tubos digitales
def drawGap (): # intervalo
turtle.penup ()
turtle.fd (5)
def main ():
turtle.setup (800, 350, 200, 200)
turtle.penup ()
turtle.fd (-300)
turtle.pensize (5)
drawDate (time.strftime ('% Y-% m =% d +', time.gmtime ()))
turtle.hideturtle ()
turtle.done ()
main () El
resultado de ejecución es el siguiente: