• 字符串、文件操作,英文词频统计预处理


    1.字符串操作:

    1.1解析身份证号:生日、性别、出生地等。

    # -*- coding : utf-8 -*-
    IdCard=input('请你输入18位身份证号码')
    while(len(IdCard)!=18):
        print('你输入的身份证号码长度有误,请你重新输入')
        IdCard=input()
    if(len(IdCard)==18):
        print('你的身份证号码为'+IdCard)
    year=IdCard[6:10];
    month=IdCard[10:12];
    day=IdCard[12:14];
    print("你的出生年月日为:"+year+""+month+""+day+"");
    if int(IdCard[16])%2 ==0:
        print("你的性别为女");
    else:
        print("你的性别为男");

    1.2 凯撒密码编码与解码

    ksmm=input('请输入你要加密的英文单词:')
    str=''
    ksmm=ksmm.lower()
    for i in range(len(ksmm)):
        ksmm.split()
        if(ord(ksmm[i]) >=99 and ord(ksmm[i]) <=999):
            str=str + (chr(ord(ksmm[i])+7))
        else:
            str = str + ksmm[i]
    print(str)

    1.3网址观察与批量生成

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

          

    2.英文词频统计预处理

    • 下载一首英文的歌词或文章或小说,保存为utf8文件。
    • 从文件读出字符串。
    • 将所有大写转换为小写
    • 将所有其他做分隔符(,.?!)替换为空格
    • 分隔出一个一个的单词
    • 并统计单词出现的次数。
    f = open('C:\Users\unliee\Desktop\hello_1.txt','r',encoding='utf-8')
    text = f.read()
    print(text)
    print(text.split())
    print(text.count('big'),text.count('world'))
    f.close()

     

     

  • 相关阅读:
    Java程序员必知的8大排序(转载)
    Eclipse快捷键大全(转载)
    Java强引用、 软引用、 弱引用、虚引用(转)
    java数据类型二(转)
    为什么静态成员、静态方法中不能用this和super关键字(转)
    POJ 2002
    POJ 3126的教训
    POJ 3349
    POj 1105解题报告
    POJ 3278
  • 原文地址:https://www.cnblogs.com/lb2016/p/10472100.html
Copyright © 2020-2023  润新知