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

  • 相关阅读:
    02-Java 数组和排序算法
    Spring Security 入门
    mysql外键理解
    redis能否对set数据的每个member设置过期时间
    Redis sortedset实现元素自动过期
    mysql之触发器trigger
    一篇很棒的 MySQL 触发器学习教程
    mysql触发器
    云游戏
    mysql触发器个人实战
  • 原文地址:https://www.cnblogs.com/cgz123/p/8609908.html
Copyright © 2011-2022 走看看