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

    综合练习:画一面五星红旗

    import turtle
    
    def mygoto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def drawWJX(r):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(r)
            turtle.right(144)
        turtle.end_fill()
    
    turtle.setup(600,400,0,0)
    turtle.bgcolor('red')
    turtle.color("yellow")
    turtle.fillcolor("yellow")
    
    mygoto(-260,120)
    drawWJX(120)
    
    for i in range(2):
        mygoto(-120+i*50, 180-i*35)
        turtle.right(22)
        drawWJX(40)
    
    for i in range(2):
        mygoto(-80 -i * 40, 75 - i * 55)
        turtle.left(44)
        drawWJX(40)
    
    turtle.hideturtle()
    turtle.done()
    

      

    字符串练习:

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

    取得校园新闻的编号

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

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

    产生python文档的网址

    str1='https://docs.python.org/3/library/turtle.html'
    print(str1.replace('turtle','python'))

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

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

    S2='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    S3='.html'
    for i in range(2,10):
        S=S2+str(i)+S3
        print(S)
    

      

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

    用函数得到校园新闻编号

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

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

    str='So tonight I am gonna get him got a rendezvous at seven  Faire amour toujours, so funny. Wanna spend all of this money  Should I wear a dress and high heels? Should I go out in my blue jeans?  He is the boy I met in my dreams. And I tell you girls: He is unbelievable    Sisters, only sometimes   You can meet the kind of boy who will always give you joy  Then grab him, never let him. Take him deep into your world  Be aware of their girls. He is so unbelievable   Finally it is me, see me happy. Today I have found him  He is the boy of my dreams and he is unbelievable '
    print(str.count("am"))
    print(str.count("I"))
    print(str.replace(",", " "))
    

      

  • 相关阅读:
    CSUOJ 2192: Wells弹键盘 (dp)
    Gym101981I Magic Potion(最大流)
    BZOJ2588: Count on a tree 主席树
    C#添加多个Sheet表
    DataTable排序,检索,合并
    检索 COM 类工厂中 CLSID 为 {} 的组件时失败,原因是出现以下错误: 80070005
    C#获取URL参数值
    JQuery爱好者们的福音 jQuery EasyUI 开源插件套装 完全替代ExtJS
    12个ajax弹出层效果
    CSS完美兼容IE6/IE7/FF的通用方法
  • 原文地址:https://www.cnblogs.com/04JC/p/8613434.html
Copyright © 2011-2022 走看看