Python基础综合练习

from turtle import *


def mygoto(x, y):
    up()
    goto(x, y)
    down()


def draw(r):
    begin_fill()
    for i in range(5):
        forward(r)
        right(144)
    end_fill()


setup(700, 500)
bgcolor('red')
color('yellow')
speed(6)
fillcolor('yellow')
hideturtle()

mygoto(-300, 150)
draw(100)
mygoto(-190, 220)
draw(45)
mygoto(-140, 150)
draw(45)
mygoto(-140, 90)
draw(45)
mygoto(-190, 40)
draw(45)
done()

字符串练习:

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

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

>>> addr1='http://news.gzcc.cn/html/2017/xiaoyuanxinwen'
>>> addr2='.html'
>>> for i in range(2,10):
    print(addr1+str(i)+addr2)

 

 

练习字符串内建函数:

>>> addr='    http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
>>> addr.strip
<built-in method strip of str object at 0x007952E0>
>>> print(addr)
    http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

 

posted @ 2018-03-19 09:49  126刘畅  阅读(93)  评论(0编辑  收藏  举报