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')
  • 相关阅读:
    封装好的PHP分页类,简单好用--在开源看到的,取回来自己用
    php网站判断用户是否是手机访问的方法
    三种php连接access数据库方法
    php防止SQL注入详解及防范
    mysql sql语句大全
    java util 中set,List 和Map的使用
    web开发——写一个简单的表格导出操作
    JSP登录页面使用Enter键登录【转】
    PL/SQL 将旧表的一些字段赋值给新的表中的字段的做法
    PL/SQL设置主键自增
  • 原文地址:https://www.cnblogs.com/knight-hui/p/7542364.html
Copyright © 2011-2022 走看看