1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #coding: utf-8 from tkinter import * # 導入所有的數學函式 from math import * # 導入數學函式後, 圓周率為 pi # deg 為角度轉為徑度的轉換因子 deg = pi / 180. frame = Frame() frame.master.title( "繪圖範例" ) frame.pack() canvas = Canvas(width = 800 , height = 800 , bg = 'white' ) canvas.pack(expand = YES, fill = BOTH) def plotline(): for i in range ( 0 , 500 , 50 ): canvas.create_line( 0 , i, 500 , i) #canvas.create_line(i, 0, i, 500) def polygon(r = 100 ,cx = 150 ,cy = 150 ,offset = 30 ): for i in range ( 270 , 270 + 360 ,offset): x0 = cx + r * cos(i * deg) y0 = cy + r * sin(i * deg) x1 = cx + r * cos((i + offset) * deg) y1 = cy + r * sin((i + offset) * deg) canvas.create_line(x0,y0,x1,y1) def plot(): for i in range ( 0 , 600 , 30 ): canvas.create_line( 400 - i, 350 - i, 500 + i, 350 - i) canvas.create_line( 500 + i, 350 - i, 500 + i, 450 + i) canvas.create_line( 500 + i, 450 + i, 400 - i, 450 + i) canvas.create_line( 400 - i, 450 + i, 400 - i, 350 - i) plotline() polygon() mainloop() |
1 2 3 4 5 6 7 8 9 10 11 12 | s = "applenkajkljkhapplejgaa" pos = 0 count = 0 while ( 1 ): pos = s.find( "apple" ,pos) if (pos = = - 1 ): break pos = pos + 1 count = count + 1 print (count) print (s.count( "apple" )) |
沒有留言:
張貼留言