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

  • 相关阅读:
    Hibernate之HQL查询
    Java设计模式----状态模式(State)
    Java设计模式----备忘录模式(Memento)
    Java设计模式----命令模式(Command)
    Java设计模式----责任链模式(Chain of Responsibility)
    Java基础小知识
    Hibernate检索策略
    Java设计模式----观察者模式(Observer)
    Google代码实验室
    Codeforces Round #257 (Div. 2) 前四题
  • 原文地址:https://www.cnblogs.com/cgz123/p/8609908.html
Copyright © 2011-2022 走看看