import turtle, datetime
def drawLine(draw): #繪制單段數碼管
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
turtle.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)
turtle.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)
turtle.left(180)
turtle.penup()
turtle.fd(20)
def drawDate(date): #獲得要輸出的數字
for i in date:
drawDigit(eval(i)) #注意: 通過eval()函數將數字變為整數
def main():
turtle.setup(800, 350, 200, 200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
drawDate(datetime.datetime.now().strftime('%Y%m%d'))
turtle.hideturtle()
main()
import turtle
def drawGap():
turtle.penup()
turtle.forward(10)
def drawLine(draw): # 繪制單段數碼管
drawGap()
turtle.pendown() if draw else turtle.penup()
turtle.forward(40)
drawGap()
turtle.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)
turtle.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)
turtle.left(180)
turtle.penup() # 為繪制後續數字確定位置
turtle.forward(20) # 未確定後續數字確定位置
def drawDate(date): # 獲得要輸出的數字
turtle.pencolor("red")
for i in reversed(range(date)):
nums = str(i)
for num in nums:
drawDigit(eval(num)) # 通過eval將字符串編程整數
turtle.clear()
width = len(nums)
turtle.forward(-80 * width)
# 畫一段長度是40,左右各空10,畫完之後前進20,做好准備畫下一個數字,回退應退,80
def main():
turtle.setup(600, 300, 200, 200)
turtle.penup()
turtle.forward(-100)
turtle.pensize(15)
turtle.speed("fast")
drawDate(12)
turtle.done()
turtle.hideturtle()
main()
I think the decision made two