zoukankan      html  css  js  c++  java
  • python练习 238

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

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

    字符串练习:

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

    取得校园新闻的编号

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

     

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

    产生python文档的网址

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

     

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

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

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

     

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

    用函数得到校园新闻编号

    #广州商学院的新闻网址为url="http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0308/9005.html"
    url="http://news.gzcc.cn/html/2018/xiaoyuanxinwen_0308/9005.html"
    print(url.split('_',2)[1].rstrip('.html'))
    

     

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

    sing='''You were my everythingthis goes out to someone that was 
    once the most important person in my life 
    i didn't realize it at the time 
    i can't forgive myself for the way i treated you so 
    i don't really expect you to either 
    it's just... i don't even know 
    just listen... 
    you're the one that i want, the one that i need 
    the one that i gotta have just to succeed 
    when i first saw you, i knew it was real 
    i'm sorry about the pain i made you feel 
    that wasn't me; let me show you the way 
    i looked for the sun, but it's raining today 
    i remember when i first looked into your eyes 
    it was like god was there, heaven in the skies 
    i wore a disguise 'cause i didn't want to get hurt 
    but i didn't know i made everything worse 
    you told me we were crazy in love 
    but you didn't care when push came to shove 
    if you loved me as much as you said you did 
    then you wouldn't have hurt me like i ain't shit 
    now you pushed me away like you never even knew me 
    i loved you with my heart, really and truly 
    i guess you forgot about the times that we shared 
    when i would run my fingers through your hair 
    late nights, just holding you in my arms 
    i don't know how i could do you so wrong 
    i really wanna show you i really need to hold you 
    i really wanna know you like no one could else know you 
    you're number one, always in my heart 
    and now i can't believe that our love is torn apart 
    refrain:i need you and 
    i miss you and 
    i want you and 
    i love you 'cause 
    i wanna hold you, 
    i wanna kiss you 
    you were my everything 
    and i really miss you (x2) 
    i knew you gonna sit and play this with your new man 
    and then sit and laugh as you're holding his hand 
    the thought of that just shatters my heart 
    it breaks in my soul and it tears me apart 
    at times we was off i was scared to show you 
    now i wanna hold you until i can't hold you 
    without you, everything seems strange 
    your name is forever planted in my brain 
    damn it, i'm insane, 
    take away the pain 
    take away the hurt 
    baby, we can make it work 
    what about when you 
    looked into my eyes 
    told me you loved me 
    as you would hugged me 
    i guess everything you said was a lie 
    i think about it, it brings tears to my eyes 
    now i'm not even a thought in your mind 
    i can see clearly, my love is not blind 
    refrain 
    i just wish everything could have turned out differently 
    i had a special feeling about you 
    i thought maybe you did too 
    you would understand, but... 
    no matter what, you'll always be in my heart 
    you'll always be my baby 
    our first day, it seemed so magical 
    i remember all the time that i had with you 
    remember when you first came to my house? 
    you looked like an angel wearing that blouse 
    we hit it off, i knew it was real 
    but now i can't take all the pain that i feel 
    reach in your heart, i know i'm still there 
    i don't wanna hear that you no longer care 
    remember the times? remember when we kissed? 
    i didn't think you would ever do me like this 
    i didn't think you'd wanna see me depressed 
    i thought you'd be there for me, this i confess 
    you said you were my best friend, was that a lie? 
    now i'm nothing to you, you're with another guy 
    i tried, i tried, i tried, and i'm trying 
    now on the inside it feels like i'm dying 
    refrain 
    [talking] and i do miss you 
    i just thought we were meant to be 
    i guess now, we'll never know 
    the only thing i want is for you to be happy 
    whether it be with me, or without me 
    i just want you to be happy '''
    
    print(sing.count('me')) #统计该歌曲出现me的次数
    print(sing.replace(" ",",")) #将空格用","代替
    print(sing.split()) #使用空格将每个单词分开
    

     

  • 相关阅读:
    018_STM32程序移植之_串口接收中文
    003_软件安装之_Visual Studio 2012
    001_C#我的第一个串口上位机软件
    017_STM32程序移植之_AS608指纹模块
    016_STM32程序移植之_舵机
    015_STM32程序移植之_NRF24L01模块
    014_STM32程序移植之_L298N电机驱动模块
    002_89C52_Proteus_DAC0832_输出50HZ,正弦波,三角波,矩形波,锯齿波
    001_89C52之_Proteus_ADC0809采集电压
    001_电子工程师招聘笔试题及详细解析
  • 原文地址:https://www.cnblogs.com/xujinpei/p/8620420.html
Copyright © 2011-2022 走看看