• 字符串操作练习:星座、凯撒密码、99乘法表、词频统计预处理


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

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

    2.实例:恺撒密码的编码

    s=input("请输入明文:")
    t=ord('a')
    print("密文是:",end='')
    for i in s:
          if t<=ord(i)<=ord('z'):
                print(chr(t+(ord(i)-t+3)%26),end=' ')
          else:
                print(i,end=' ')
                

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

    s=input("输入姓名:")
    print("输出姓名:{0: ^4}".format(s))

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

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

    5.打出99乘法表

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

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

    love='''An empty street An empty house 
    A hole inside heart 
    I'm all alone and the rooms 
    Are getting smaller 
    I wonder how I wonder why 
    I wonder where they are 
    The days we had 
    The songs we sang together 
    And oh! my love 
    I'm holding on forever 
    Reaching for a love 
    That seems so far 
    So I say a litter prayer 
    No my dream will take me there 
    Where the skies are blue to see you 
    
    My love 
    And hope my dream will take me there 
    Where the skies are blue to see you 
    once again my love 
    Overseas from coast to coast 
    Find a place I love the most 
    Where the fields are green 
    To see you once again 
    My love '''
    print('My Love'.center(60,'-'))
    print(love.count('love'))
    print(love.replace(',',' '))

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

    import webbrowser as web
    web.open_new_tab("www.baidu.com")
    for i in range(1,3):
        web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+str(i)+".html")

  • 相关阅读:
    苹果将首次采用HTML5直播发布会 狼人:
    Python 3.2 alpha 2发布 狼人:
    下一代Linux文件系统Btrfs走向成熟 狼人:
    Hello! 404 狼人:
    退格回车控制台输入密码
    poj 3233 Matrix Power Series
    地址参考clang: error: linker command failed with exit code 1 (use v to see invocation)
    文本截断JQuery为textarea添加maxlength,并且兼容IE
    代码下载Html5初探视频元素video示例
    c# 限制textbox的输入范围和长度(长度不用maxlength方法)
  • 原文地址:https://www.cnblogs.com/liulingyuan/p/7542292.html
Copyright © 2020-2023  润新知