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

    import turtle
    
    def mygoto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def drawwjx(x):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(x)
            turtle.right(144)
        turtle.end_fill()
    
    turtle.color("red")
    turtle.speed(10)
    mygoto(-300,200)
    turtle.begin_fill()
    for i in range(2):
        turtle.forward(576)
        turtle.right(90)
        turtle.forward(384)
        turtle.right(90)
    turtle.end_fill()
    
    turtle.color("yellow")
    mygoto(-262,123)
    drawwjx(110)
    
    for i in range(4):
        x=1
        if i in [0,3]:
            x=0
        mygoto(-120+x*30, 160-i*41)
        turtle.left(15-i*15)
        drawwjx(30)
    
    turtle.hideturtle()
    turtle.done()
    

      

    字符串练习:

    http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html

    取得校园新闻的编号

    url ="http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html"
    print(url[-14:-5])
    

     

    https://docs.python.org/3/library/turtle.html

    产生python文档的网址

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

     

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

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

    for i in range(0,5):
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i))
    

     

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

    用函数得到校园新闻编号

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

     用函数统计一歌词(文章、小说)中单词出现的次数,替换标点符号为空格,用空格进行分词。

    str = '''I have a small bedroom. 
    There is a bed on the right corner of the room. 
    There is a desk and a chair beside the bed. 
    There is a computer and a lamp on the desk. 
    There is a bookshelf between the bed and the desk. 
    There are thousands of books on the bookshelf. 
    Although my bedroom is small, it's always clean and tidy. 
    So I like my bedroom very much.'''
    print(str.count("There"))
    print(str.replace(","," "))
    print(str.split())
    

      

  • 相关阅读:
    虚基类练习 动物1
    UVa 10820
    hdu1027 Ignatius and the Princess II (全排列 & STL中的神器)
    在windows下安装redmine及相关问题
    批量导出表数据到CSV文件
    轻松学习Ionic (二) 为Android项目集成Crosswalk(更新官方命令行工具)
    swift第一章
    socket编程演示样例(多线程)
    谋哥:玩App怎么赚钱(三)
    Oracle database wrc运行报错ORA-15557
  • 原文地址:https://www.cnblogs.com/cgq520/p/8619398.html
Copyright © 2011-2022 走看看