Python基础综合练习

impo sys
print(sys.argv)
import turtle
turtle.bgcolor('red')
turtle.color('yellow')
turtle.fillcolor('yellow')
turtle.setup(600,400,0,0)

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

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

moveto(-260,120)
turtle.begin_fill()
for i in range(5):
    turtle.forward(120)
    turtle.right(144)
turtle.end_fill()

moveto(-120,160)
turtle.left(31)
print(40)
turtle.setheading(0)

moveto(-80,130)
turtle.left(-18)
print(40)
turtle.setheading(0)

moveto(-80,70)
turtle.left(0)
print(40)


moveto(-120,20)
turtle.left(31)
print(40)
turtle.hideturtle()
turtle.done()

 

 

http://news.gzcc.cn/html/2017/xiaoyuanxinwe
n_1027/8443.html

取得校园新闻的编号

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

结果:

https://docs.python.org/3/library/turtle.ht
ml

产生python文档的网址

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

结果:

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

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

add3='http://news.gzcc.cn/html/xiaoyuanxinwen/'
add4='.html'
for i  in range(4):
    result=add3+str(i)+add4
    print(result)

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

用函数得到校园新闻编号

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

 

用函数统计一歌词中单词出现的次数

 

str6='Every morning you greet me Small and white Clean and bright You look happy to meet me Blossom of snow May you bloom and grow Bloom and grow forever Edelweiss, edelweiss Bless my homeland forever '
print(str6.count('and'))

 

posted @ 2018-03-20 16:10  195陈冠中  阅读(109)  评论(0编辑  收藏  举报