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())
  • 相关阅读:
    Javascript&Html-系统对话框
    Javascript&Html-延迟调用和间歇调用
    Javascript&Html-弹出窗口的屏蔽程序
    iPhone屏幕旋转
    iPhone深度学习-ARM
    xCode控制台的使用-应用闪退原因跟踪
    IOS-内存检测以及优化
    Javascript-Array
    http与https的区别
    Nginx:处理HTTP请求
  • 原文地址:https://www.cnblogs.com/Ming-jay/p/8609854.html
Copyright © 2011-2022 走看看