Python基础综合练习

综合练习:画一面五星红旗

import turtle

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

def drawWJX(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.bgcolor('red')
turtle.color("yellow")
turtle.fillcolor("yellow")

mygoto(-260,120)
drawWJX(120)

for i in range(2):
    mygoto(-120+i*50, 180-i*35)
    turtle.right(22)
    drawWJX(40)

for i in range(2):
    mygoto(-80 -i * 40, 75 - i * 55)
    turtle.left(44)
    drawWJX(40)

turtle.hideturtle()
turtle.done()

  

字符串练习:

http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

取得校园新闻的编号

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

https://docs.python.org/3/library/turtle.html

产生python文档的网址

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

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

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

S2='http://news.gzcc.cn/html/xiaoyuanxinwen/'
S3='.html'
for i in range(2,10):
    S=S2+str(i)+S3
    print(S)

  

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

用函数得到校园新闻编号

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

用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。

str='So tonight I am gonna get him got a rendezvous at seven  Faire amour toujours, so funny. Wanna spend all of this money  Should I wear a dress and high heels? Should I go out in my blue jeans?  He is the boy I met in my dreams. And I tell you girls: He is unbelievable    Sisters, only sometimes   You can meet the kind of boy who will always give you joy  Then grab him, never let him. Take him deep into your world  Be aware of their girls. He is so unbelievable   Finally it is me, see me happy. Today I have found him  He is the boy of my dreams and he is unbelievable '
print(str.count("am"))
print(str.count("I"))
print(str.replace(",", " "))

  

原文地址:https://www.cnblogs.com/04JC/p/8613434.html