Python 基础综合练习
import turtle
def mygoto(x,y):
turtle.up()
turtle.goto(x,y)
turtle.down()
def drawwjx(x):
turtle.begin_fill()
for i in range(5):
turtle.forward(x)
turtle.right(144)
turtle.end_fill()
turtle.color("red")
turtle.speed(10)
mygoto(-300,200)
turtle.begin_fill()
for i in range(2):
turtle.forward(576)
turtle.right(90)
turtle.forward(384)
turtle.right(90)
turtle.end_fill()
turtle.color("yellow")
mygoto(-262,123)
drawwjx(110)
for i in range(4):
x=1
if i in [0,3]:
x=0
mygoto(-120+x*30, 160-i*41)
turtle.left(15-i*15)
drawwjx(30)
turtle.hideturtle()
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(0,5):
print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(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"))
用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。
str = '''I have a small bedroom.
There is a bed on the right corner of the room.
There is a desk and a chair beside the bed.
There is a computer and a lamp on the desk.
There is a bookshelf between the bed and the desk.
There are thousands of books on the bookshelf.
Although my bedroom is small, it's always clean and tidy.
So I like my bedroom very much.'''
print(str.count("There"))
print(str.replace(","," "))
print(str.split())
浙公网安备 33010602011771号