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

    
    

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

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

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

    s = input('input your name:')
    s = str(s)
    print('{0: ^75}'.format(s))

    实例:恺撒密码的编码

    def Caesar_code(s,t):
        s = str(s)
        t = int(t)
        l = []
        for i in range(len(s)):
            l.append(chr(ord(s[i])+t))
            print(chr(ord(s[i])+t),end='')
    Caesar_code('huanglinsheng',3)

    实例:打出99乘法表

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

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

    GDP = input('中华人民共和国国内生产总值(GDP):')
    GDP = str(GDP)
    Year  = input('输入年份:')
    Year = int(Year)
    print('{}   :    {}'.format(Year,GDP))

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

    s = '''英文歌 (5, 4, 3, 2, 1)-群星
    I plant a flower, plant a tree
    Plant your hopes and plant your dreams
    And let them grow until… (5, 4, 3, 2, 1)
    I’ll take you somewhere that is near
    Seas of blue and fields of green
    May the heartaches soon be healed
    I’m just a woman but I’m for real
    As strong as every man can be
    So put your faith in me…
    I'm what I am and what you see
    Only say the words that I would keep
    I'm one of you
    
    '''
    print(s.count('I'))
    print(s.replace('I','i'))
    print(s.replace('I','my'))
    print(s.replace('a',' '))

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

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

  • 相关阅读:
    svn版本控制器在vs2013中的使用
    在本地环境用虚拟机win2008 sever搭建VS2013 + SVN 代码版本控制环境
    luogu 2422 良好的感觉
    loj 10181 绿色通道
    luogu 2569 [SCOI2010]股票交易
    luogu 3946 ことりのおやつ(小鸟的点心)
    luogu 2865 [USACO06NOV]路障Roadblocks
    luogu 4554 小明的游戏
    luogu 2411 白银莲花池 && luogu 1606 Lilypad Pond
    luogu 2850 [USACO06DEC]虫洞Wormholes
  • 原文地址:https://www.cnblogs.com/huanglinsheng/p/7542296.html
Copyright © 2011-2022 走看看