1 impo sys 2 print(sys.argv) 3 import turtle 4 turtle.bgcolor('red') 5 turtle.color('yellow') 6 turtle.fillcolor('yellow') 7 turtle.setup(600,400,0,0) 8 9 def moveto(x,y): 10 turtle.up() 11 turtle.goto(x,y) 12 turtle.down() 13 14 def print(n): 15 turtle.begin_fill() 16 for i in range(5): 17 turtle.forward(n) 18 turtle.right(144) 19 turtle.end_fill() 20 21 moveto(-260,120) 22 turtle.begin_fill() 23 for i in range(5): 24 turtle.forward(120) 25 turtle.right(144) 26 turtle.end_fill() 27 28 moveto(-120,160) 29 turtle.left(31) 30 print(40) 31 turtle.setheading(0) 32 33 moveto(-80,130) 34 turtle.left(-18) 35 print(40) 36 turtle.setheading(0) 37 38 moveto(-80,70) 39 turtle.left(0) 40 print(40) 41 42 43 moveto(-120,20) 44 turtle.left(31) 45 print(40) 46 turtle.hideturtle() 47 turtle.done()
運行結果圖以下:html
網址:python
http://news.gzcc.cn/html/2017/xiaoyuanxinwe
n_1027/8443.htmlide
取得校園新聞的編號函數
str1='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' print(str1[-9:-5])
運行結果以下:spa
網址:3d
https://docs.python.org/3/library/turtle.ht
mlcode
產生python文檔的網址htm
str2='https://docs.python.org/3/library/turtle.html' print(str2.replace("turtle","python"))
運行結果:blog
網址:ip
http://news.gzcc.cn/html/xiaoyuanxinwen/4.h
tml
產生校園新聞的一系列新聞頁網址
add3='http://news.gzcc.cn/html/xiaoyuanxinwen/' add4='.html' for i in range(4): result=add3+str(i)+add4 print(result)
練習字符串內建函數:
strip,lstrip,rstrip,split,count
用函數獲得校園新聞編號
str5='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' print(str5.split('_',2)[1].rstrip('.html'))
用函數統計一歌詞中單詞出現的次數
str=「Sometimes it's hard to define If falling stars are hiding in your eyes Just watching you made me cry Cause now I know you'll never ever get off my mind I never thought all those beautiful words can't describe A little of your kindness, a bit of your light There's nothing I can't give up for your smile Whatever it takes, I'll make it alright. 」 print(str.count('I'))