python基础综合练习
import turtle
def mygoto(x, y):
turtle.up()
turtle.goto(x, y)
turtle.down()
def drawwwu(r):
turtle.begin_fill()
for i in range(5):
turtle.forward(r)
turtle.right(144)
turtle.end_fill()
turtle.setup(600,400,0,0)
turtle.color('yellow')
turtle.bgcolor('red')
mygoto(-260,130)
drawwwu(100)
for i in range(4):
x=1
if i in [0, 3]:
x=0
mygoto(-125+x*30,160-i*30)
turtle.left(15-i*17)
drawwwu(30)
mygoto(0, 0)
turtle.hideturtle()
turtle.done()

2.字符串练习:
2.1
http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html
取得校园新闻的编号:
str = "http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
num = str.rstrip(".html").split("_")[1]
print(num)
2.2
https://docs.python.org/3/library/turtle.html
产生python文档的网址:
str1 = "https://docs.python.org/3.6/library/" str2 = ".html" str =str1+"turtle"+str2 print(str)
2.3
http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址:
for i in range(2,10):
str = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
print(str)
3.练习字符串内建函数:strip,lstrip,rstrip,split,count,replace
3.1用函数得到校园新闻编号
url = 'http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
print(url.rstrip('.html').split('_') [1])
3.2用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词
>>> sing='''
... 两只老虎,两只老虎,
...
... 跑得快,跑得快,
...
... 一只没有耳朵,
...
... 一只没有尾巴,
...
... 真奇怪!真奇怪!。
...
... 两只老虎,两只老虎,
...
... 跑得快,跑得快,
...
... 一只没有耳朵,
...
... 一只没有尾巴,
...
... 真奇怪!真奇怪!
... '''
>>> sing.count('一只')
4

浙公网安备 33010602011771号