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

    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 goto(x,y):
        turtle.up();
        turtle.goto(x,y);
        turtle.down;
     
    def drawxwjx(x):
        turtle.begin_fill()
        for i in range(5):
            turtle.forward(x)
            turtle.right(144)
        turtle.end_fill()
     
    turtle.setup(600,400,0,0)
    turtle.color("yellow")
    turtle.bgcolor("red")
     
    goto(-260,120)
    turtle.begin_fill()
    for i in range(5):
        turtle.forward(100)
        turtle.right(144)
    turtle.end_fill()
     
    for i in range(4):
        x = 1
        if i in [0,3]:
            x = 0
        goto(-120+x*45,180-i*45)
        turtle.left(15-i*15)
        drawxwjx(30)
     
    turtle.hideturtle()
     
    turtle.done()
    

    字符串练习:

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

    取得校园新闻的编号

    str='http://news.gzcc.cn/html/2017/xiaoyuanxinwen_1027/8443.html'
    print(str[-9:-5])
    

    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(2,10):
        print('http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(str(i)));
    

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

    用函数得到校园新闻编号

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

    用函数统计一歌词中单词出现的次数

    str='''
    You were the shadow to my light
    你是我生命之光中的一道暗影
    Did you feel us
    你能理解我们吗
    Another Star
    另一颗行星
    You fade away
    你逐渐消失
    Afraid our aim is out of sight
    恐惧我们的目标迷失在视野
    Wanna see us
    希望我们互相理解
    Alive
    活着
    Where are you now
    你身在何方?
    Where are you now
    你身在何方?
    Where are you now
    你身在何方?
    Was it all in my fantasy
    难道这一切都在我的幻想里
    Where are you now
    你身在何方?
    Were you only imaginary
    你只是虚幻的不存在吗?
    Where are you now
    你身在何方?
    Atlantis
    亚特兰蒂斯
    Under the sea
    在海底
    Under the sea
    在海底
    Where are you now
    你身在何方?
    Another dream
    另外的梦想
    The monster's running wild inside of me
    狂野的怪兽驰聘在我心深处
    I'm faded
    我憔悴不堪
    I'm faded
    我憔悴不堪
    So lost, I'm faded
    所以迷失,憔悴不堪
    I'm faded ~~~
    我憔悴不堪
    So lost, I'm faded
    所以迷失,憔悴不堪
    These shallow waters never met
    那些从未见过的水中之影
    What i needed
    我需要的
    I'm letting go
    只是顺其自然
    A deeper dive
    深沉海底
    Eternal silence of the sea
    无尽的沉默于海中
    I'm breathing
    我的呼吸声
    Alive.
    活着
    Where are you now
    你身在何方?
    Where are you now
    你身在何方?
    Under the bright but faded lights
    明亮的灯光却已经黯然失色
    You set my heart on fire
    你点燃了我的心火
    Where are you now
    你身在何方?
    Where are you now
    你身在何方?
    ...
    ...
    Where are you now
    你身在何方?
    Atlantis
    亚特兰蒂斯
    Under the sea
    在海底
    Under the sea
    在海底
    Where are you now
    你身在何方?
    Another dream
    另外的梦想
    The monster's running wild inside of me
    狂野的怪兽驰聘在我心深处
    I'm faded
    我憔悴不堪
    I'm faded
    我憔悴不堪
    So lost, I'm faded
    所以迷失,憔悴不堪
    I'm faded ~~~
    我憔悴不堪
    So lost, I'm faded
    所以迷失,憔悴不堪
    '''
    print(str.count("you"))
    print(str.replace(","," "))
    

      

     

  • 相关阅读:
    sort()函数与qsort()函数
    个人作业——软件工程实践总结作业
    个人作业——软件评测
    软件工程实践2019第五次作业
    软件工程实践2019第四次作业
    软件工程实践2019第三次作业
    软件工程实践2019第二次作业
    期末大作业
    第7次实践作业
    第6次实践作业
  • 原文地址:https://www.cnblogs.com/wlh0329/p/8616339.html
Copyright © 2011-2022 走看看