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')
  • 相关阅读:
    signalr推送消息
    WebApi2跨域问题
    iTextSharp生成pdf的一个简单例子
    遇到的错误记录
    AutoMapper用法
    visual studio 2015中的webapi生成helpPage,页面不显示方法说明问题解决
    visualstudio 2013 mysql entityframework :实体模型无法添加,闪退
    webapi相关知识
    2016年4月14日
    2016年4月13日
  • 原文地址:https://www.cnblogs.com/knight-hui/p/7542364.html
Copyright © 2011-2022 走看看