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(',',' '))
    

      

  • 相关阅读:
    宣布降低Windows Azure 存储和计算的价格
    物联网操作系统的概念和特点
    基于Windows8与Visual Studio11开发第一个内核驱动程序
    在 C++ 中使用 PPL 进行异步编程
    现实世界的Windows Azure:采访Figlo的全球合作伙伴支持经理Nathan Brouwer
    物联网操作系统随笔
    Windows Azure Toolkit for Windows 8 Consumer Preview的升级版发布了
    上海招聘会场所
    理解 Delphi 的类(十) 深入方法[3] 调用时参数分割
    关于类的入门例子(7): 遍历窗体的所有父类
  • 原文地址:https://www.cnblogs.com/zhiling123/p/8619725.html
Copyright © 2011-2022 走看看