1、逢7跳過小游戲:從1-100之間,遇到帶7的數字或者7的倍數跳過。 1 for i in range(1,101): 2 if i == 7 or i % 10 == 7 or i // 10 == 7: 3 continue 4 else: 5 print(i,end = ",") 2、七段數 ...
1、逢7跳過小游戲:從1-100之間,遇到帶7的數字或者7的倍數跳過。
1 for i in range(1,101): 2 if i == 7 or i % 10 == 7 or i // 10 == 7: 3 continue 4 else: 5 print(i,end = ",")
2、七段數位管的繪製:模擬電子管顯示屏顯示日期
1 import turtle 2 import time 3 def drawGap(): 4 turtle.penup() 5 turtle.fd(5) 6 def drawLine(draw): 7 drawGap() 8 turtle.pendown() if draw else turtle.penup() 9 turtle.fd(40) 10 drawGap() 11 turtle.right(90) 12 #開始繪製 13 def drawDigit(digit): 14 drawLine(True) if digit in (2,3,4,5,6,8,9) else drawLine(False) 15 drawLine(True) if digit in (0,1,3,4,5,6,7,8,9) else drawLine(False) 16 drawLine(True) if digit in (0,2,3,5,6,8,9) else drawLine(False) 17 drawLine(True) if digit in (0,2,6,8,9) else drawLine(False) 18 turtle.left(90) 19 drawLine(True) if digit in (0,4,5,6,8,9) else drawLine(False) 20 drawLine(True) if digit in (0,2,3,4,5,6,7,8,9) else drawLine(False) 21 drawLine(True) if digit in (0,1,2,3,4,7,8,9) else drawLine(False) 22 turtle.left(180) 23 turtle.penup() 24 turtle.fd(20) 25 def drawDate(date): 26 turtle.pencolor("red") 27 for i in date: 28 if i == "-": 29 turtle.write('年',font=("Arial",18,"normal")) 30 turtle.pencolor("green") 31 turtle.fd(40) 32 elif i == "=": 33 turtle.write('月',font=("Arial",18,"normal")) 34 turtle.pencolor("green") 35 turtle.fd(40) 36 elif i == "+": 37 turtle.write('日',font=("Arial",18,"normal")) 38 else: 39 drawDigit(eval(i)) 40 def main(): 41 turtle.setup(800,350,200,200) 42 turtle.penup() 43 turtle.fd(-300) 44 turtle.pensize(5) 45 drawDate(time.strftime('%Y-%m=%d+',time.gmtime())) 46 turtle.hideturtle() 47 turtle.done() 48 main()