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')
  • 相关阅读:
    R学习之——R用于文本挖掘(tm包)
    【转】基于LDA的Topic Model变形
    Windows操作系统实习之读者写者问题
    应用《开场白》ios源码分享
    一个美式英语发音的app开源
    20款优秀的移动产品原型和线框图设计工具
    sqlite 数据库在ios中的使用
    28个UI免费漂亮的切换开关PSD下载
    ios应用程序生命周期
    Ludei HTML5平台将于今年夏季支持WebGL 3D技术
  • 原文地址:https://www.cnblogs.com/knight-hui/p/7542364.html
Copyright © 2011-2022 走看看