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

      

  • 相关阅读:
    关于回调地狱
    node.js 关于跨域和传递给前台参数
    关于js的当前日期的格式化,和两个日期之间的相减的天数
    CSS 关于让页面的高度达到电脑屏幕的底部
    前端 为什么我选择用框架而不是Jquery
    关于webpack打包图片的路径问题
    关于webpack打包js和css
    微信小程序网络请求的setDate
    WinSocket聊天程序实例(多线程)
    Orcal的JDBC数据连接方式
  • 原文地址:https://www.cnblogs.com/04JC/p/8613434.html
Copyright © 2011-2022 走看看