码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2019-03-06 00:36:10      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:txt   read   close   小说   png   utf-8   mamicode   ima   解析   

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()

技术图片

 

 技术图片

 

 

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

标签:txt   read   close   小说   png   utf-8   mamicode   ima   解析   

原文地址:https://www.cnblogs.com/lb2016/p/10472100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!