zoukankan      html  css  js  c++  java
  • 字符串操作练习:星座、凯撒密码、99乘法表、词频统计预处理

    99乘法表

    for i in range(1,10,1):
        for j in range(1,i+1,1):
            print('%d*%d=%d'%(i,j,i*j),end='	')
        print('
    ')

    中国GDP

    >>> print('中华人民共和国国内生产总值(GDP){0:,.2f}亿元(2015年)'.format(689136.89))
    中华人民共和国国内生产总值(GDP)689,136.89亿元(2015年)
    >>> 

    12星座

    >>> for i in range (12):
        print(chr(9800+i))
    
        
    ♈
    ♉
    ♊
    ♋
    ♌
    ♍
    ♎
    ♏
    ♐
    ♑
    ♒
    ♓
    >>> for i in range (12):
        print(chr(9800+i),end='	')
    
        
    ♈    ♉    ♊    ♋    ♌    ♍    ♎    ♏    ♐    ♑    ♒    ♓    
    >>> for i in range (12):
        print(chr(9800+i),end=' ')
    
        
    ♈ ♉ ♊ ♋ ♌ ♍ ♎ ♏ ♐ ♑ ♒ ♓ 
    >>> 

    凯撒密码(+3)

    kaisa=input('明文:')
    s=ord('a')
    for i in kaisa:
        if s<= ord(i)<=ord('z'):
            print(chr(s+(ord(i)-s+3)%26),end='')
        else:
            print(i,end='')
            

     {}的格式控制<序号><填充><对齐>宽度<千分位><精度><类型>

    >>> print('输出的数是:{0:,.4f}'.format(1995.112))
    输出的数是:1,995.1120
    >>> p='hpk'
    >>> print('字符串{0:*>8}'.format(p))
    字符串*****hpk

    输入姓名,格式输出:占4位、居中、不足4字的以空格填充 

    a=input('请输入姓名(四个字以内):')
    if len(a)==4:
        print('{}'.format(a))
    else:
        print('{0: >4}'.format(a))
        

    下载一首英文的歌词或文章,统计单词出现的次数,将所有,.?!替换为空格,将所有大写转换为小写

    kang='''I’m at a payphone trying to call home
    All of my change I’ve spent it on you
    Where are the times gone baby
    It’s all wrong, where are the plans we made for two
    Yeah, I, I know it’s hard to remember
    The people we used to be
    It’s even harder to picture
    That you’re not here next to me
    You said it’s too late to make it
    But is it too late to try?
    And then that time that you wasted
    All of our bridges burned down
    I’ve wasted my nights
    You turned out the lights
    Now I’m paralyzed
    Still stucked in that time when we called it love
    But even the sun sets in paradise
    I’m at a payphone trying to call home
    All of my change i’ve spent on you
    Where are the times gone baby
    It’s all wrong, where are the plans we made for two
    If happy ever after did exist
    I would still be holding you like this
    And all those fairytales are full of it
    One more stupid love song I’ll be sick
    You turned your back on tomorrow
    Cause you forgot yesterday
    I gave you my love to borrow
    But just gave it away
    You can’t expect me to be fine
    I don’t expect you to care
    I know I said it before
    But all of our bridges burned down
    I’ve wasted my nights
    You turned out the lights
    Now I’m paralyzed
    Still stucked in that time when we called it love
    But even the sun sets in paradise
    I’m at a payphone trying to call home
    All of my change I’ve spent on you
    Where are the times gone baby
    It’s all wrong, where are the plans we made for two
    If happy ever after did exist
    I would still be holding you like this
    And all those fairytales are full of it
    One more stupid love song I’ll be sick
    Now I’m at a payphone…
    Now work that sh-t
    I’ll be right here spending all this money while you sitting round
    Wondering why wasn’t you who came out from nothing
    Made it from the bottom
    Now when you see me I’m strutting
    And all of my cause a way to push up a button
    Telling me the chances I blew up or whatever you call it
    Switched the number to my phone
    So you never can call it
    Don’t need my name, or my show
    Swish you can tell it I’m ballin’
    What a shame coulda got picked
    Had a really good game but you missed your last shot
    So you talk about who you see at the top
    Or what you could’ve saw
    But sad to say it’s over for it
    Phantom roll out valet open doors
    Where’s the car way, got what you was looking for
    Now ask me who they want
    So you can go take that little piece of sh-t with you
    I’m at a payphone trying to call home
    All of my change I’ve spent on you
    Where are the times gone baby
    It’s all wrong, where are the place we made for two
    If happy ever after did exist
    I would still be holding you like this
    And all these fairytales are full of it
    One more stupid love song I’ll be sick
    Now i’m at a payphone'''
    print('payphone的个数为')
    print(kang.count('payphone'))
    print('全文改为小写')
    print(kang.lower())

    用webbrowser打开校园新闻

    import webbrowser as web
    url='http://news.gzcc.cn/html/xiaoyuanxinwen/'
    web.open_new_tab(url)
    for i in range(2,5):
        web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')

  • 相关阅读:
    多线程下的调用上下文 : CallContext
    MongoDB入门实战教程(7)
    MongoDB入门实战教程(6)
    MongoDB入门实战教程(5)
    MongoDB入门实战教程(4)
    MongoDB入门实战教程(3)
    MongoDB入门实战教程(2)
    MongoDB入门实战教程(1)
    ASP.NET 5 with Dapr 初体验
    2021成都.NET开发者Connect线下活动
  • 原文地址:https://www.cnblogs.com/kang8823/p/7541743.html
Copyright © 2011-2022 走看看