zoukankan      html  css  js  c++  java
  • Python基础综合练习(五角星)

    综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。
    import turtle
    
    def mygoto(x,y):
           turtle.up()
           turtle.goto(x,y)
           turtle.down()
    
    def drawwjx(x,y,z):
           turtle.fillcolor('yellow')
           turtle.right(z)
           turtle.forward(y)
           turtle.right(144)
           turtle.begin_fill()
           for i in range(4):
                  turtle.forward(x)
                  turtle.right(144)
           turtle.end_fill()
    
    
    
    turtle.setup(600,400,0,0)
    turtle.bgcolor('red')
    turtle.color('yellow')
    mygoto(-250, 135);
    drawwjx(100,100,0);
    
    
    
    
    mygoto(-120,175);
    drawwjx(30,30,10);
    
    
    mygoto(-85,145);
    drawwjx(30,30,10);
    
    
    mygoto(-85,95);
    drawwjx(30,30,-20);
    
    
    mygoto(-120,65);
    drawwjx(30,30,10);
    
    
    turtle.hideturtle()
    turtle.done()

    字符串练习:

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

    取得校园新闻的编号

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

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

    用函数得到校园新闻编号

    url='http://news.gzcc.cn/html/xiaoyuanxinwen_0308/9005.html'
    print(url.strip('.html').split('_')[1])

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

    url2='Oh oh oh oh oooh Oh oh oh oh oooh Oh oh oh oh oooh Oh oh oh oh oooh I messed up tonight, I lost another fight I still mess up but I ll just start again I keep falling down, I keep on hitting the ground I always get up now to see whats next Birds dont just fly, they fall down and get up Nobody learns without getting it won I wont give up, no I won t give in Til I reach the end, then I ll start again No I wont leave, I wanna try everything I wanna try even though I could fail I wont give up, no I won t give in Til I reach the end and then I ll start again No I won t leave, I wanna try everything I wanna try even though I could fail Oh oh oh oh oooh Try everything Oh oh oh oh oooh Try everything Oh oh oh oh oooh Try everything Oh oh oh oh oooh Look at how far you ve come, you filled your heart with love Baby you ve done enough that cut your breath Dont beat yourself up, dont need to run so fast Sometimes we come last, Til I reach the end and then ll start again No I won'
    print(url2.split())
    print(url2.count('oh'))
    print(url2.lstrip('o'))
  • 相关阅读:
    拦截器getmodel方法什么时候被调用(没搞懂有什么鸟用,自己搭的项目中用到了这个)
    Convention插件的使用(会涉及content目录,jsp必须放入这个下面才能映射成功基于注解的配置)
    Spring组件扫描<context:component-scan/>使用详解
    Eclipse从数据库逆向生成Hibernate带注解的实体类
    HibernateTool的安装和使用(Eclipse中)
    将一字符串首字母转大写
    二分(折半)查找算法
    按位与运算符
    注解及自定义注解
    根据前序遍历和中序遍历得出后序遍历
  • 原文地址:https://www.cnblogs.com/wwc000/p/8609576.html
Copyright © 2011-2022 走看看