Python基础综合练习

综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。

import turtle


def Mygoto(x,y):
    turtle.up()
    turtle.goto(x,y)
    turtle.down()

def Drawstar(x):
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(x)
        turtle.right(144)
    turtle.end_fill()

turtle.setup(800,600,0,0)
turtle.color("yellow")
turtle.bgcolor("red")
turtle.fillcolor("yellow")

Mygoto(-300,80)
Drawstar(120)

for i in range(4):
    x=1
    if i in[0,3]:
        x=0
    Mygoto(-135+x*30,155-i*45)
    turtle.left(25-i*15)
    Drawstar(30)

turtle.hideturtle()
turtle.done()

  

字符串练习:

http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

取得校园新闻的编号

 

str1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html"
for i in range(2, 10):
    str2 = str1.format(i)
    str3 = str2.rstrip(".html").split("/")[-1]
    print(str3)

  

https://docs.python.org/3/library/turtle.html

产生python文档的网址

 


for i in range(2,11):
str="http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
print(str)

  

http://news.gzcc.cn/html/xiaoyuanxinwen/4.html

产生校园新闻的一系列新闻页网址

 

for i in range(2,11):
str="http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
print(str)

  

练习字符串内建函数:strip,lstrip,rstrip,split,count,replace

用函数得到校园新闻编号

x="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
y=x.rstrip(".html").split("_")[1]
print(y)

  

用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。

str = '''
Passion is sweet
Love makes weak
You said you cherised freedom so
You refused to let it go
Follow your faith
Love and hate
never failed to seize the day
Don't give yourself away
Oh when the night falls
And your all alone
In your deepest sleep
What are you dreeeming of
My skin's still burning from your touch
Oh I just can't get enough
I said I wouldn't ask for much
But your eyes are dangerous
So the tought keeps spinning in my head
Can we drop this masquerade
I can't predict where it ends
If you're the rock I'll crush against
Trapped in a crowd
Music's loud
I said I loved my freedom too
Now im not so sure i do
All eyes on you
Wings so true
Better quit while your ahead
Now im not so sure i am
Oh when the night falls
And your all alone
In your deepest sleep
What are you dreaming of
My skin's still burning from your touch
Oh I just can't get enough
I said I wouldn't ask for much
But your eyes are dangerous
So the thought keeps spinning in my head
Can we drop this masquerade
I can't predict where it ends
If you're the rock I'll crush against
My soul, my heart
If your near or if your far
My life, my love
You can have it all
Oh when the night falls
And your all alone
In your deepest sleep
What are you dreaming of
My skin's still burning from your touch
Oh I just can't get enough
I said I wouldn't ask for much
But your eyes are dangerous
So the thought keeps spinning in my head
Can we drop this masquerade
I can't predict where it ends
If you're the rock I'll crush against
If you're the rock i'll crush against'''
print(str.count("my"))
print(str.count("you"))
print(str.count("just"))
print(str.count("rock"))
print(str.replace(","," "))

  

posted @ 2018-03-21 20:41  229曾颖鑫  阅读(134)  评论(0)    收藏  举报