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

  • 相关阅读:
    asp.net中合并DataGrid行
    将Asp.Net页面输出到EXCEL里去····
    清空Sql数据库日志等操作
    opengl 教程(14) 摄像机控制(1)
    awk使用技巧
    opengl 教程(10) index draw
    opengl 教程(12) 投影矩阵
    opengl 教程(9) 顶点属性插值
    opengl 教程(15) 摄像机控制(2)
    opengl 教程(11) 平移/旋转/缩放
  • 原文地址:https://www.cnblogs.com/cgz123/p/8609908.html
Copyright © 2011-2022 走看看