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

    Pycharm开发环境设置与熟悉。

    练习基本输入输出:

    print('你好,{}.'.format(name))

    print(sys.argv)

    库的使用方法:

    import ...

    from ... import ...

    条件语句:

        if (abs(pos()))<1:

            break

    循环语句:

    for i in range(5):

    while True:

    函数定义:

    def mygoto(x,y):

    def drawjx(r):

    综合练习:画一面五星红旗,将代码与运行截图发布博客交作业。

    import turtle
    
    def mygoto(x,y):
        turtle.up()
        turtle.goto(x,y)
        turtle.down()
    
    def draw(z):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(z)
            turtle.right(144)
        turtle.end_fill()
    
    turtle.setup(700, 500, 0, 0)
    turtle.color("yellow")
    turtle.bgcolor("red")
    turtle.fillcolor("yellow")
    turtle.hideturtle()
    
    mygoto(-300,150)
    draw(100)
    
    for i in range(4):
        x=1;
        if i in [0,3]:
            x=0;
        mygoto(-210+x*50,205-i*50)
        turtle.left(0-i*10)
        draw(30)
    mygoto(0,0)
    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"
    num = url.rstrip(".html").split("_")[1]
    print(num)
    

      截图

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

    产生python文档的网址

    addr1='https://docs.python.org/3/library/'
    addr2='.html'
    addr=addr1+'turtle'+addr2
    print(addr)
    

      截图

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

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

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

      截图

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

    str='Hello world'
    print(str.lstrip())
    print(str.count("e"))
    print(str.split())
    print(str.replace('world','everyone'))
    

      截图

    用函数得到校园新闻编号

    addr1='http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'
    for i in range(1,5):
        addr2= addr1.format(i)
        addr3=addr2.rstrip('.html').split('/')[-1]
        print(addr3)
    

      截图

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

    str='''
       King Athamus of northern Greece had two children, Phrixus and Helle.After he left his first wife 
    and mar ried Ino,a wicked woman,the two children received all the cruel treatment that a stepmother 
    coulddevise ,At one timethe kingdom was ruined by a famine.
       Ino persuaded her credulous husband intobelievingthat his son,Phrixus,was the actual cause of the 
    disaster,and should be sacrificed to Zeus to endit.The poor boy was then placed on the altar and was 
    about tobe knifed when a ram with goldenfleecewas sent down by thegods and carried off the two children 
    on its back.
        As they flew over the strait that divides Asia from Europe,Helle,faint at the vast expanse of 
    waterbelow ,fell into the sea and was drowned.Thus the sea of Helle,Hellespont,became the ancient 
    name of the strip of water.Her brother kept on and arrived in Colchis on the eastern shore of the Black 
    Sea.There he sacrificed the ram to Zeus and gave its golden fleece to King Aeetes,who nailed it on a 
    sacred tree and put a sleepless dragon incharge .'''
    print(str.count('to'))
    print(str.replace(',','  '))
    

      截图

  • 相关阅读:
    纯CSS垂直居中的四种解决方案
    UTF-8 UTF-16 UTF-32 最根本的区别?
    js中==和===区别
    关于端口的定义, 为什么要有端口
    变量命名规范
    使用枚举enum
    js中, 用变量或对象作为if或其他条件的表达式
    使用jquery-panzoom来实现图片或元素的放大缩小
    使用mescroll来实现移动端页面上拉刷新, 下拉加载更多功能
    angularjs常用事件
  • 原文地址:https://www.cnblogs.com/cktcom/p/8614816.html
Copyright © 2011-2022 走看看