Python基础综合练习

import  turtle

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

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

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

mygoto(-260,120)
draw(90)

for i in range(4):
   x=1
   if i in[0,3]:
      x = 0
   mygoto(-120+x*40,160-i*40)
   turtle.left(15-i*15)
   draw(30)

turtle.done()


取得校园新闻的编号

str1 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
print(str1[-9:-5])

产生python文档的网址

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

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

area1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/"
area2 = ".html"

for i in range(2,13):
   area = area1 + str(i) + area2
   str3 = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
   print(str3,area)

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

用函数得到校园新闻编号

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

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

str5 = '''Come with me for a little ride, see the shadows passing by
Look at the sun and see the clouds turn to faces in the sky
We've been awake all night, shattered dreams all around
Close your sad, sad eyes we will be safe and sound

Come with me for a little ride, see the shadows passing by
Look at the sun and see the clouds turn to faces in the sky
Daydreaming lightly through the rainAll's forgiven on a summer train

Come with me for a little ride, see the shadows passing by
Seems we are a thousand miles away from last night
As you sigh in my ear, kiss the rain goodbye

Come with me for a little ride, see the shadows passing by
Look at the sun and see the clouds turn to faces in the sky
Daydreaming lightly through the rain
All's forgiven on a summer train

Come with me for a little ride, see the shadows passing by
Come away with me, it's gonna be all right just breathe
Come away with me, it's gonna be all right you'll see

And the wind .... this train is flying us all through the rain, I fear
And the sky is getting brighter with every mile
And it all seems clear

Come with me for a little ride, see the shadows passing by
Look at the sun and see the clouds turn to faces in the sky
Daydreaming lightly through the rain
All's forgiven on a summer train

Come with me for a little ride, see the shadows passing by
Come away with me, it's gonna be all right just breathe
Come away with me, it's gonna be all right you'll see

Come away with me, it's gonna be all right just breathe
Come away with me, it's gonna be all right you'll see, you'll see
Come away with me'''

print(str5.count("Come"))
print(str5.replace(","," "))
print(str5.split())

 

转载于:https://www.cnblogs.com/Ming-jay/p/8609854.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值