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

    import turtle
    from turtle import *
    
    turtle.setup(600,400,0,0)
    turtle.color('yellow')
    turtle.bgcolor('red')
    turtle.fillcolor('yellow')
    
    def my_go_to(x, y):
        turtle.up()
        turtle.goto(x, y)
        turtle.down()
    
    def draw_five(r):
        turtle.begin_fill()
    
        for i in range(5):
            turtle.forward(r)
            turtle.left(-144)
        turtle.end_fill()
    
    my_go_to(-230, 100)
    draw_five(100)
    
    for i in range(4):
        x = 1
        if i in [0, 3]:
            x = 0
        my_go_to(-120+x*50, 150-i*40)
        turtle.left(15-i*15)
        draw_five(30)
    
    my_go_to(0, 0)
    
    hideturtle()
    done()
    

      

    综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。

    字符串练习:

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

    取得校园新闻的编号

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

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

    产生python文档的网址

    a1 = 'http://docs.python.org/3/labrary/'
    a2 = '.html'
    a3 = a1+'turtle'+a2
    print(a3)

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

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

    for i in range (2, 5):
        news_page = 'http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i)
        print(news_page)
    

      

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

    用函数得到校园新闻编号

    url = 'http://news.gzcc.cn/2017/xiaoyuanxinwen_1027/8443.html'
    new_url = url.rstrip('.html').split('_')[1]
    print(new_url)
    

      

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

    word = '''
    good evening, ladies and gentlemen, honorable judges and distinguished guest! this is alex time! ha-ha…my topic today is to show our gratitude to people around you.
      then what is gratitude? at the moment a well-known song comes into my mind.
      yes, that is called heart of feel grateful.
      my heart is filled up with gratitude because i’m with you/your make me courageous to be myself from cradle to the grave/so now i wanna thank for destiny/i’ll cherish the flower when it blooms until falls.
      the poetic lyric tells us that gratitude is actually a state of mind.once upon a time, the pilgrims took the may flower ship to north america.
      they started a new life there although a lot of difficulties and hardships they encountered.
      after a long-time work, they got a big harvest.
      the pilgrims had a feast in 1621 near plymouth, massachusetts, which is often referred to as the first thanksgiving.
      people show their sincere gratitude towards the god, the nature, the earth, the river, the indians and themselves.
      moreover the 1621 feast has become a model for the thanksgiving celebration in the united states.
      so we can see gratitude is an action to take.how can we express our gratitude? it’s never a simple question to answer.
      gratitude is a rare jewel, not a piece of cake, i know.
      but how can we expect such big events happening now and then? how can we be ready to say thank you ahead of time? how can we always hope to be grateful to everything and everyone for their dignity and generosity? sometimes i may ask to myself.
      is it moral? is it honest? is it beneficial? is it necessary? or the most interesting one, is it ridiculous? ha-ha…so in my opinion, we’d better concentrate on our life’s details.
      keep your eyes open to your daily life.
      yes! a shining smile is supposed to be gratitude.
      a thank-you note is supposed to be gratitude.
      a soulful watch is supposed to be gratitude.
      as far as a baby’s crying on his arrival is supposed to be gratitude.
      and even fallen leaves in autumn are supposed to be gratitude.
      so the person, who stands here giving you a speech, is also showing his gratitude.at last, what’s the significance of showing our gratitude? a proverb says that gratitude is the sign of noble souls.
    '''
    new_word = word.replace(",", " ").replace("!", " ").replace(".", " ")
    print(new_word)
    print(new_word.count("is"))
    print(new_word.split(" "))
    

      结果展示:

    1027/844
    
    http://docs.python.org/3/labrary/turtle.html
    
    http://news.gzcc.cn/html/xiaoyuanxinwen/2.html
    http://news.gzcc.cn/html/xiaoyuanxinwen/3.html
    http://news.gzcc.cn/html/xiaoyuanxinwen/4.html
    
    1027/8443
    
    good evening  ladies and gentlemen  honorable judges and distinguished guest  this is alex time  ha-ha…my topic today is to show our gratitude to people around you 
      then what is gratitude? at the moment a well-known song comes into my mind 
      yes  that is called heart of feel grateful 
      my heart is filled up with gratitude because i’m with you/your make me courageous to be myself from cradle to the grave/so now i wanna thank for destiny/i’ll cherish the flower when it blooms until falls 
      the poetic lyric tells us that gratitude is actually a state of mind once upon a time  the pilgrims took the may flower ship to north america 
      they started a new life there although a lot of difficulties and hardships they encountered 
      after a long-time work  they got a big harvest 
      the pilgrims had a feast in 1621 near plymouth  massachusetts  which is often referred to as the first thanksgiving 
      people show their sincere gratitude towards the god  the nature  the earth  the river  the indians and themselves 
      moreover the 1621 feast has become a model for the thanksgiving celebration in the united states 
      so we can see gratitude is an action to take how can we express our gratitude? it’s never a simple question to answer 
      gratitude is a rare jewel  not a piece of cake  i know 
      but how can we expect such big events happening now and then? how can we be ready to say thank you ahead of time? how can we always hope to be grateful to everything and everyone for their dignity and generosity? sometimes i may ask to myself 
      is it moral? is it honest? is it beneficial? is it necessary? or the most interesting one  is it ridiculous? ha-ha…so in my opinion  we’d better concentrate on our life’s details 
      keep your eyes open to your daily life 
      yes  a shining smile is supposed to be gratitude 
      a thank-you note is supposed to be gratitude 
      a soulful watch is supposed to be gratitude 
      as far as a baby’s crying on his arrival is supposed to be gratitude 
      and even fallen leaves in autumn are supposed to be gratitude 
      so the person  who stands here giving you a speech  is also showing his gratitude at last  what’s the significance of showing our gratitude? a proverb says that gratitude is the sign of noble souls 
    
    26
    ['
    good', 'evening', '', 'ladies', 'and', 'gentlemen', '', 'honorable', 'judges', 'and', 'distinguished', 'guest', '', 'this', 'is', 'alex', 'time', '', 'ha-ha…my', 'topic', 'today', 'is', 'to', 'show', 'our', 'gratitude', 'to', 'people', 'around', 'you', '
    u3000u3000then', 'what', 'is', 'gratitude?', 'at', 'the', 'moment', 'a', 'well-known', 'song', 'comes', 'into', 'my', 'mind', '
    u3000u3000yes', '', 'that', 'is', 'called', 'heart', 'of', 'feel', 'grateful', '
    u3000u3000my', 'heart', 'is', 'filled', 'up', 'with', 'gratitude', 'because', 'i’m', 'with', 'you/your', 'make', 'me', 'courageous', 'to', 'be', 'myself', 'from', 'cradle', 'to', 'the', 'grave/so', 'now', 'i', 'wanna', 'thank', 'for', 'destiny/i’ll', 'cherish', 'the', 'flower', 'when', 'it', 'blooms', 'until', 'falls', '
    u3000u3000the', 'poetic', 'lyric', 'tells', 'us', 'that', 'gratitude', 'is', 'actually', 'a', 'state', 'of', 'mind', 'once', 'upon', 'a', 'time', '', 'the', 'pilgrims', 'took', 'the', 'may', 'flower', 'ship', 'to', 'north', 'america', '
    u3000u3000they', 'started', 'a', 'new', 'life', 'there', 'although', 'a', 'lot', 'of', 'difficulties', 'and', 'hardships', 'they', 'encountered', '
    u3000u3000after', 'a', 'long-time', 'work', '', 'they', 'got', 'a', 'big', 'harvest', '
    u3000u3000the', 'pilgrims', 'had', 'a', 'feast', 'in', '1621', 'near', 'plymouth', '', 'massachusetts', '', 'which', 'is', 'often', 'referred', 'to', 'as', 'the', 'first', 'thanksgiving', '
    u3000u3000people', 'show', 'their', 'sincere', 'gratitude', 'towards', 'the', 'god', '', 'the', 'nature', '', 'the', 'earth', '', 'the', 'river', '', 'the', 'indians', 'and', 'themselves', '
    u3000u3000moreover', 'the', '1621', 'feast', 'has', 'become', 'a', 'model', 'for', 'the', 'thanksgiving', 'celebration', 'in', 'the', 'united', 'states', '
    u3000u3000so', 'we', 'can', 'see', 'gratitude', 'is', 'an', 'action', 'to', 'take', 'how', 'can', 'we', 'express', 'our', 'gratitude?', 'it’s', 'never', 'a', 'simple', 'question', 'to', 'answer', '
    u3000u3000gratitude', 'is', 'a', 'rare', 'jewel', '', 'not', 'a', 'piece', 'of', 'cake', '', 'i', 'know', '
    u3000u3000but', 'how', 'can', 'we', 'expect', 'such', 'big', 'events', 'happening', 'now', 'and', 'then?', 'how', 'can', 'we', 'be', 'ready', 'to', 'say', 'thank', 'you', 'ahead', 'of', 'time?', 'how', 'can', 'we', 'always', 'hope', 'to', 'be', 'grateful', 'to', 'everything', 'and', 'everyone', 'for', 'their', 'dignity', 'and', 'generosity?', 'sometimes', 'i', 'may', 'ask', 'to', 'myself', '
    u3000u3000is', 'it', 'moral?', 'is', 'it', 'honest?', 'is', 'it', 'beneficial?', 'is', 'it', 'necessary?', 'or', 'the', 'most', 'interesting', 'one', '', 'is', 'it', 'ridiculous?', 'ha-ha…so', 'in', 'my', 'opinion', '', 'we’d', 'better', 'concentrate', 'on', 'our', 'life’s', 'details', '
    u3000u3000keep', 'your', 'eyes', 'open', 'to', 'your', 'daily', 'life', '
    u3000u3000yes', '', 'a', 'shining', 'smile', 'is', 'supposed', 'to', 'be', 'gratitude', '
    u3000u3000a', 'thank-you', 'note', 'is', 'supposed', 'to', 'be', 'gratitude', '
    u3000u3000a', 'soulful', 'watch', 'is', 'supposed', 'to', 'be', 'gratitude', '
    u3000u3000as', 'far', 'as', 'a', 'baby’s', 'crying', 'on', 'his', 'arrival', 'is', 'supposed', 'to', 'be', 'gratitude', '
    u3000u3000and', 'even', 'fallen', 'leaves', 'in', 'autumn', 'are', 'supposed', 'to', 'be', 'gratitude', '
    u3000u3000so', 'the', 'person', '', 'who', 'stands', 'here', 'giving', 'you', 'a', 'speech', '', 'is', 'also', 'showing', 'his', 'gratitude', 'at', 'last', '', 'what’s', 'the', 'significance', 'of', 'showing', 'our', 'gratitude?', 'a', 'proverb', 'says', 'that', 'gratitude', 'is', 'the', 'sign', 'of', 'noble', 'souls', '
    ']
    
    Process finished with exit code 0
    

      

  • 相关阅读:
    VBS基础篇
    AcWing249 蒲公英(分块)
    CF1338B Edge Weight Assignment(思维+dfs)
    CF785E Anton and Permutation(分块)
    UCF Local Programming Contest 2015(Practice)D题
    AcWing851 spfa求最短路
    CF479E Riding in a Lift (dp)
    AcWing267 莫基亚(CDQ分治)
    P4093 [HEOI2016/TJOI2016]序列 (CDQ分治)
    2019ICPC南昌区域赛C题 And and Pair(数位dp)
  • 原文地址:https://www.cnblogs.com/-hjd/p/8609845.html
Copyright © 2011-2022 走看看