Python基础综合练习

 1 import turtle
 2  
 3 def mygoto(x,y):
 4     turtle.up()
 5     turtle.goto(x,y)
 6     turtle.down()
 7  
 8 def drawwjx(x):
 9     turtle.begin_fill()
10     for i in range(5):
11         turtle.forward(x)
12         turtle.right(144)
13     turtle.end_fill()
14 
15 turtle.speed(10)
16 turtle.color("red")
17 mygoto(-300,200)
18 turtle.begin_fill()
19 for i in range(2):
20  turtle.forward(576)
21     turtle.right(90)
22     turtle.forward(384)
23     turtle.right(90)
24 turtle.end_fill()
25  
26 turtle.color("yellow")
27 mygoto(-262,123)
28 drawwjx(110)
29  
30 for i in range(4):
31     x=1
32     if i in [0,3]:
33         x=0
34     mygoto(-120+x*30, 160-i*41)
35     turtle.left(15-i*15)
36     drawwjx(30)
37  
38 turtle.hideturtle()
39 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文档的网址

 

url ="https://docs.python.org/3/library/turtle.html"
print(url.replace("turtle","python"))

  

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

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

for i in  range(2,10):
    print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(str(i)));

 

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

用函数得到校园新闻编号

url ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
print (url.split('_',2)[1].rstrip(".html"))

 

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

Let it go

Let it go

Can't hold you back anymore

Let it go
Let it go
Turn my back and slam the door
.

The snow blows white on the mountain tonight
Not a footprint to be seen

A kingdom of isolation and it looks like I'm the Queen

The wind is howling like the swirling storm inside

Couldn't keep it in, heaven knows I tried

Don't let them in, don't let them see
Be the good girl
You always had to be
Conceal, don't feel
Don't let them know

Well, now they know
.
Let it go
Let it go

Can't hold you back anymore

Let it go
Let it go

Turn my back and slam the door

And here I stand, and here I'll stay
Let it go
Let it go

The cold never bothered me anyway
.
It's funny how some distance

Makes everything seem small

And the fears that once controlled me
Can't get to me at all

Up here in the cold thin air
I finally can breathe

I know i left a life behind but I'm to relieved to grieve
.
Let it go
Let it go

Can't hold you back anymore

Let it go
Let it go
Turn my back and slam the door

And here I stand

And here I'll stay

Let it go
Let it go

The cold never bothered me anyway
.
Standing frozen in the life I've chosen

You won't find me, the past is so behind me

Buried in the snow
.

Let it go
Let it go

Can't hold you back anymore

Let it go
Let it go

Turn my back and slam the door

And here I stand

And here I'll stay

Let it go
Let it go

The cold never bothered me anyway

na na na na na na
Let it go na na na

you go

Let it go
Let it go

Let it go
1 print(str.count("go"))
2 print(str.replace(","." "))

 

 

 
 

 

转载于:https://www.cnblogs.com/xiaozheng303/p/8620076.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值