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

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

    代码如下:

    import turtle
    
    # turtle.shape('turtle')
    
    turtle.setup(600, 400, 0, 0)
    turtle.color('yellow')
    turtle.bgcolor('red')
    turtle.fillcolor('yellow')
    
    def mygoto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    
    def drawwjx(x):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(x)
            turtle.right(144)
        turtle.end_fill()
    
    mygoto(-260,120)
    drawwjx(100)
    
    for i in range(4):
        x=1
        if i in [0,3]:
            x=0
        mygoto(-120+x*50,150-i*35)
        turtle.left(15-i*15)
        drawwjx(30)
    

     结果如图所示:

     

    字符串练习:

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

    取得校园新闻的编号

    #取得校园新闻的编号
    url='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
    print(url[-14:-5])
    

      

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

    产生python文档的网址

    addr1 = 'https://docs.python.org/3/library/'
    addr2 = '.html'
    addr = addr1 + 'turtle' + addr2
    print(addr)
    

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

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

    add1='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    add2='.html'
    for i in range(1,5):
        print(add1+str(i)+add2)

      

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

    用函数得到校园新闻编号

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

      

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

    str='''If I walk would you run,If I stop would you come,If I say you're the one,would you believe me,If I ask you to stay,would you show me the way,Tell me what to say so you don't leave me,The world is catching up to you,While your running away to chase your dream,It's time for us to make a move,
    Cause we are asking one another to change,And maybe I'm not ready,But I'm trying for your love,I can hide up above,I will try for your love,We've been hiding enough,If I sing you a song would you sing along,Or wait till I'm gone oh how we push and pull,If I give you my heart would you just play the part,
    Or tell me it's the start of something beautiful,Am I catching up to you,
    While your running away to chase your dreams,It's time for us to face the truth,Cause we are coming to each other to change,And maybe I'm not ready,But I'm trying for your love,I can hide up above,I will try for your love,
    We've been hiding enough,I will try for your love,I can hide up above,If I walk would you run,If I stop would you come...'''
    
    print(str.count('I'))
    
    print(str.replace(',',' '))
    

      

  • 相关阅读:
    Codeforces 46D Parking Lot
    矩阵快速幂
    Codeforces 295A Greg and Array
    hihocoder 1154 Spring Outing
    51NOD 1400 序列分解
    最短路之Dijkstra算法
    连通性1 求无向图的low值
    用数组实现临接表
    hihocoder 1181 欧拉路.二
    TCP多线程聊天室
  • 原文地址:https://www.cnblogs.com/zhiling123/p/8619725.html
Copyright © 2011-2022 走看看