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

    impo sys
    print(sys.argv)
    import turtle
    turtle.bgcolor('red')
    turtle.color('yellow')
    turtle.fillcolor('yellow')
    turtle.setup(600,400,0,0)
    
    def moveto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def print(n):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(n)
            turtle.right(144)
        turtle.end_fill()
    
    moveto(-260,120)
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(120)
        turtle.right(144)
    turtle.end_fill()
    
    moveto(-120,160)
    turtle.left(31)
    print(40)
    turtle.setheading(0)
    
    moveto(-80,130)
    turtle.left(-18)
    print(40)
    turtle.setheading(0)
    
    moveto(-80,70)
    turtle.left(0)
    print(40)
    
    
    moveto(-120,20)
    turtle.left(31)
    print(40)
    turtle.hideturtle()
    turtle.done()

     

    http://news.gzcc.cn/html/2017/xiaoyuanxinwe
    n_1027/8443.html

    取得校园新闻的编号

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

    结果:

    https://docs.python.org/3/library/turtle.ht
    ml

    产生python文档的网址

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

    结果:

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

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

    add3='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    add4='.html'
    for i  in range(4):
        result=add3+str(i)+add4
        print(result)

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

    用函数得到校园新闻编号

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

    用函数统计一歌词中单词出现的次数

    str6='Every morning you greet me Small and white Clean and bright You look happy to meet me Blossom of snow May you bloom and grow Bloom and grow forever Edelweiss, edelweiss Bless my homeland forever '
    print(str6.count('and'))

  • 相关阅读:
    CentOS查看CPU信息、位数、多核信息
    Linux常用命令大全
    chmod命令详细用法
    tar命令的详细解释
    yum和rpm命令详解
    LeetCode 241. Different Ways to Add Parentheses
    LeetCode 139. Word Break
    LeetCode 201. Bitwise AND of Numbers Range
    LeetCode 486. Predict the Winner
    LeetCode 17. Letter Combinations of a Phone Number
  • 原文地址:https://www.cnblogs.com/cgz123/p/8609908.html
Copyright © 2011-2022 走看看