tkinter.py
#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()
find.py
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"))
沒有留言:
張貼留言