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

    输出12个星座符号,以反斜线分隔。

    for i in range(12):
        print(chr(9800+i),end='\')

    恺撒密码的编码

    m = input("请输入加密字符:")
    q=ord('a')
    p=ord('z')
    print("加密结果为")
    for i in m:
        if q<=ord(i)<=p:
            print(chr(q+(ord(i)-p+3)%26),end='')
        else:
            print(i,end='')

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

    name=input('输入姓名:')
    print('名字是:{:^4}'.format(name))

    格式化输出:中华人民共和国国内生产总值(GDP)689,136.89亿元(2015年)(千分位、2位小数,浮点数)

    print("中华人民共和国国内生产总值(GDP):{0:^-10,.3f}亿元".format(689,136.89))

    实例:打出99乘法表

    for i in range(1,10):
        for j in range(1, i+1):
                print('{}x{}={}	'.format(j, i, i*j), end='')
        print()

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

    song='''"every night in my dreams 
    i see you, i feel you,
    that is how i know you go on 
    far across the distance 
    and spaces between us 
    you have come to show you go on 
    near, far, wherever you are 
    i believe that the heart does go on 
    once more you open the door 
    and you're here in my heart 
    and my heart will go on and on 
    love can touch us one time 
    and last for a lifetime 
    and never let go till we're one 
    love was when i loved you 
    one true time i hold to 
    in my life we'll always go on 
    near, far, wherever you are 
    i believe that the heart does go on 
    once more you open the door 
    and you're here in my heart 
    and my heart will go on and on 
    there is some love that will not go away 
    you're here, there's nothing i fear,
    and i know that my heart will go on 
    we'll stay forever this way 
    you are safe in my heart 
    and my heart will go on and on"'''
    song=song.replace(',',' ')
    song=song.lower()
    print('my计数为:',song.count('my'))
    print('heart计数为:',song.count('heart'))
    print('歌词为:',song)

     

    用webbrowser,uweb.open_new_tab('url')打开校园新闻列表

    import webbrowser as web
    for i in range(2,6):
        web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+'.html')
  • 相关阅读:
    GPON和820.1p学习及资料(zt)
    modelsim(3)
    JTAG 学习 -SVF格式
    看来人工智能不可阻挡,将和网络与计算机一样服务于各行各业!
    【管理心得之二十六】职场中的“武功”
    【管理心得之二十五】组织中的骂名 ----------墙头草
    【管理心得之二十四】成功乃失败之母
    【管理心得之二十三】道是道,非常道。名可名,非常名。
    【管理心得之二十二】小人物 仰视 大授权
    【管理心得之二十一】管得少就是管得好
  • 原文地址:https://www.cnblogs.com/knight-hui/p/7542364.html
Copyright © 2011-2022 走看看