Python基础综合练习
综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。
import turtle #移动坐标 def mygoto(x,y): turtle.up() turtle.goto(x,y) turtle.down() #绘制五角星 def drawjx(r): turtle.begin_fill() for i in range(5): turtle.forward(r) turtle.right(144) turtle.end_fill() turtle.setup(600,400) turtle.color("#FAF408") turtle.bgcolor("#F40002") mygoto(-250,95) drawjx(100) mygoto(-120,150) turtle.left(45) drawjx(30) mygoto(-90,110) turtle.left(15) drawjx(30) mygoto(-90,70) turtle.left(15) drawjx(30) mygoto(-120,30) turtle.left(45) drawjx(30) turtle.done()
字符串练习:
http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html
取得校园新闻的编号
xinwen='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html' print(xinwen[45:49])
https://docs.python.org/3/library/turtle.html
产生python文档的网址
a1='https://docs.python.org/3/library/turtle.html' print(a1.replace("turtle","python"))
http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址
creatxiwnen='http://news.gzcc.cn/html/xiaoyuanxinwen/' html='.html' for i in range(5): print(creatxiwnen+str(i)+html)
用函数得到校园新闻编号
a1 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html" print (a1.split('_',2)[1].rstrip(".html"))
用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。
a5='''Waking up I see that everything is ok The first time in my life And now it's so great Slowing down I look around And I am so amazed I think about the little things That make life great I wouldn't change a thing about it This is the best feeling This innocence is brilliant I hope that it will stay This moment is perfect Please don't go away I need you now And I'll hold on to it Don't you let it pass you by I found a place so safe Not a single tear The first time in my life And now it's so clear Feel calm my belong I'm so happy here It's so strong And now I let myself be sincere I wouldn't change a thing about it This is the best feeling This innocence is brilliant I hope that it will stay This moment is perfect Please don't go away I need you now And I'll hold on to it Don't you let it pass you by It's the state of bliss you think You're dreaming It's the happiness inside That you're feeling It's so beautiful It makes you wanna cry It's the state of bliss you think You're dreaming It's the happiness inside That you're feeling It's so beautiful It makes you wanna cry It's so beautiful It makes you want to cry This innocence is brilliant It makes you want to cry This innocence is brilliant Please don't go away 'Cause I need you now And I'll hold on to it Don't you let it pass you by This innocence is brilliant I hope that it will stay This moment is perfect Please don't go away I need you now And I'll hold on to it Don't you let it pass you by ''' print(a5.count("innocence")); print(a5.replace("'"," ")) print(a5.split())