import turtle def mygoto(x, y): turtle.up() turtle.goto(x,y) turtle.down() def drawBigStar(x): turtle.begin_fill() for i in range(5): turtle.forward(x) turtle.right(144) turtle.end_fill() def drawStar(x): turtle.begin_fill() for i in range(5): turtle.forward(x) turtle.left(144) turtle.end_fill() mygoto(-250,200) turtle.color("red") turtle.fillcolor("red") turtle.begin_fill(); for i in range(2): turtle.forward(600) turtle.right(90) turtle.forward(400) turtle.right(90) turtle.end_fill() mygoto(-220,110) turtle.color("yellow") turtle.fillcolor("yellow") turtle.begin_fill() drawBigStar(100) turtle.end_fill() for i in range(4): x=1 if i in[0,3]: x=0 mygoto(-100+x*50,150-i*45) turtle.left(15-i*15) drawBigStar(30) mygoto(0,0) turtle.hideturtle() turtle.done();
字符串练习:
http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html
取得校园新闻的编号
url = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' print(url[-14:-5])
https://docs.python.org/3/library/turtle.html
产生python文档的网址
addr1 = 'https://docs.python.org/3/library/' addr2 = '.html' addr = addr1 + 'turtle' + addr2 print(addr)
http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址
for i in range(0,10): print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))
练习字符串内建函数:strip,lstrip,rstrip,split,count,replace
用函数得到校园新闻编号
str='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' print(str.rstrip('.html').split('_')[1])
用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。