zoukankan      html  css  js  c++  java
  • Python基础综合练习

    import  turtle
    
    def mygoto(x,y):
      turtle.up()
      turtle.goto(x, y)
      turtle.down()
    
    def draw(x):
     turtle.begin_fill()
     for i in range(5):
         turtle.forward(x)
         turtle.right(144)
     turtle.end_fill()
    
    turtle.setup(600,400,0,0)
    turtle.color("yellow")
    turtle.bgcolor("red")
    turtle.fillcolor("yellow")
    turtle.hideturtle()
    
    mygoto(-260,120)
    draw(90)
    
    for i in range(4):
       x=1
       if i in[0,3]:
          x = 0
       mygoto(-120+x*40,160-i*40)
       turtle.left(15-i*15)
       draw(30)
    
    turtle.done()


    取得校园新闻的编号

    str1 ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(str1[-9:-5])

    产生python文档的网址

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

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

    area1 = "http://news.gzcc.cn/html/xiaoyuanxinwen/"
    area2 = ".html"
    
    for i in range(2,13):
       area = area1 + str(i) + area2
       str3 = "http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html".format(i)
       print(str3,area)

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

    用函数得到校园新闻编号

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

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

    str5 = '''Come with me for a little ride, see the shadows passing by
    Look at the sun and see the clouds turn to faces in the sky
    We've been awake all night, shattered dreams all around
    Close your sad, sad eyes we will be safe and sound
    
    Come with me for a little ride, see the shadows passing by
    Look at the sun and see the clouds turn to faces in the sky
    Daydreaming lightly through the rainAll's forgiven on a summer train
    
    Come with me for a little ride, see the shadows passing by
    Seems we are a thousand miles away from last night
    As you sigh in my ear, kiss the rain goodbye
    
    Come with me for a little ride, see the shadows passing by
    Look at the sun and see the clouds turn to faces in the sky
    Daydreaming lightly through the rain
    All's forgiven on a summer train
    
    Come with me for a little ride, see the shadows passing by
    Come away with me, it's gonna be all right just breathe
    Come away with me, it's gonna be all right you'll see
    
    And the wind .... this train is flying us all through the rain, I fear
    And the sky is getting brighter with every mile
    And it all seems clear
    
    Come with me for a little ride, see the shadows passing by
    Look at the sun and see the clouds turn to faces in the sky
    Daydreaming lightly through the rain
    All's forgiven on a summer train
    
    Come with me for a little ride, see the shadows passing by
    Come away with me, it's gonna be all right just breathe
    Come away with me, it's gonna be all right you'll see
    
    Come away with me, it's gonna be all right just breathe
    Come away with me, it's gonna be all right you'll see, you'll see
    Come away with me'''
    
    print(str5.count("Come"))
    print(str5.replace(","," "))
    print(str5.split())
  • 相关阅读:
    转载(SQL Server 存储过程的分页)
    学会了怎么样利用捕获异常提示数据库主键重复错误
    遇到.net加了验证控件的表单无法提交的问题
    过劳死IT界杀手 [注:该文属于转载,非原创],好可怕啊!
    很喜欢的一些道理。
    学会了在DropDownList的项里加多个空格
    好东东:asp.net利用多线程执行长时间的任务,客户端显示出任务的执行进度的示例
    javascript判断字符长度最好的方法
    layui中使用layverify进行非必填整数校验
    SuppressWarnings抑制警告的关键字
  • 原文地址:https://www.cnblogs.com/Ming-jay/p/8609854.html
Copyright © 2011-2022 走看看