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


    1、凯撒密码

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

    2、星座符号

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

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

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

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

     year = input("请输入年份:")
     gdp = float(input("请输入{}年的GDP:".format(year)))
     print("中华人民共和国国内生产总值(GDP){0:,.2f}亿元({1}年)".format(gdp,year))

    6、实例:打出99乘法表

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

     

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

    geci = '''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 
    geci=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 
    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  '''
    
    
    print(geci.count('love'))
    for i in geci:
        geci=geci.replace(',',' ')
        geci=geci.replace('.',' ')
        geci=geci.replace('!',' ')
        geci=geci.replace('?',' ')
    print(geci)
    print (geci.lower())

     8、用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/xiaoyuanxinwen/'+str(i)+'.html')

  • 相关阅读:
    2019-2020-1 20175316 《信息安全系统设计基础》第5周学习总结
    2019-2020-1 20175316 《信息安全系统设计基础》第4周学习总结
    2019-2020-1 20175316 《信息安全系统设计基础》第3周学习总结
    第06组 Alpha冲刺(4/6)
    第06组 Alpha冲刺(3/6)
    第06组 Alpha冲刺(2/6)
    第06组 Alpha冲刺(1/6)
    第06组 团队Git现场编程实战
    团队项目-需求分析报告
    团队项目-选题报告
  • 原文地址:https://www.cnblogs.com/millmill/p/7542188.html
Copyright © 2020-2023  润新知