1:画五角星
import turtle turtle.bgcolor('red') turtle.fillcolor('yellow') turtle.pencolor('yellow') def draw(x): turtle.begin_fill() for i in range(5): turtle.forward(x) turtle.right(144); turtle.end_fill() def go(x, y): turtle.up() turtle.goto(x, y) turtle.down() go(-200,100) draw(100) go(-100, 200) draw(50) go(-50, 150) draw(50) go(-50, 80) draw(50) go(-100, 10) draw(50) turtle.hideturtle() input()
2:取得校园新闻的编号
str1 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
print(str1[-9:-5])
3:产生python文档的网址
str2 ="https://docs.python.org/3/library/turtle.html"
print(str2.replace("turtle","python"))
4:http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
产生校园新闻的一系列新闻页网址
url1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/"
url2 = ".html"
for i in range(2,10):
url= url1 + str(i) + url2
urlstr= "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
print(urlstr,url)
5:lsrip()函数、count()函数、replace()函数的使用
str=' hhh kkk jakshdf kk nnh dd ss gg tt ss '
'ff you you ni ni nin me me eme eme e e'
' ee e e e e e e e e nnn bb hh kk kk n hh '
'hh jj ss aa cc vv '
print(str.lstrip())
print(str.count('me'))
print(str.replace('ee','=='))
结果显示:
hhh kkk jakshdf kk nnh dd ss gg tt ss ff you you ni ni nin me me eme eme e e ee e e e e e e e e nnn bb hh kk kk n hh hh jj ss aa cc vv
4
hhh kkk jakshdf kk nnh dd ss gg tt ss ff you you ni ni nin me me eme eme e e == e e e e e e e e nnn bb hh kk kk n hh hh jj ss aa cc vv