Python综合练习

import turtle
def mygoto(x, y):
    turtle.up()
    turtle.goto(x, y)
    turtle.down()
def drow(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")
mygoto(-250,95)
drow(100)
for i in range(4):
    x=1
    turtle.right(5)
    if i in [0,3]:
        x=0
    mygoto(-135+x*30,155-i*45)
    turtle.left(20-i*15)
    drow(30)
turtle.hideturtle()
turtle.done()

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

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

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

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

产生python文档的网址

url1='https://docs.python.org/3/library/'
url2='.html'
url=url1+'turtle'+url2
print(url)

5. 练习字符串内建函数:strip,lstrip,rstrip,split,countreplace

 

str ="      I'm very handsome!   "
print(str.lstrip())
print(str.count("e"))
print(str.split())
print(str.split().replace("handsome","perfect"))

 

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

str = '''
熟悉的陌生的这种感觉
重复的曾经的那些情节
也只是怀念
一滴滴一点点一页一篇
分手了也不过三百多天
可我却害怕遇见
我懵懵懂懂过了一年
这一年似乎没有改变
守着你离开后的世界
空空如也
白天和晚上都是冬夜
悲伤的到来我从不拒绝
反正亦是空空空空如也
我懵懵懂懂过了一年
徘徊在石板路的街边
曾经笑容灿烂
如今却空空如也
一切的星光都已陨灭
得过且过是我如今速写
无所谓让痛重叠
'''
print(str.count("空空如也"))
print(str.count("白天"))

 

 

posted on 2018-03-20 16:03  242韦兴纳  阅读(191)  评论(0编辑  收藏  举报

导航