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

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

时间:2019-03-06 15:12:36      阅读:187      评论:0      收藏:0      [点我收藏+]

标签:bsp   ted   cci   air   ant   color   was   tin   print   

1.字符串操作:

身份证号解析

ID=input("请输入身份证号:")
year=ID[6:10]
mouth=ID[10:12]
day=ID[12:14]
if(int(ID[16])%2==0):
    sex=""
else:
    sex=""
print("出生日期为:%s年%s月%s日\n性别:%s"%(year,mouth,day,sex))

 

凯撒密码

plaincode=input("请输入源码:")
a=ord(a)
z=ord(z)
A=ord(A)
Z=ord(Z)
for i in plaincode:
    if a<=ord(i)<=z :
        print(chr(a+(ord(i)-z+3)%26),end="")
    elif A<=ord(i)<=Z:
        print(chr(A + (ord(i) - Z + 3) % 26), end="")
    else:
        print(i,end="")

 网址观察与批量生成

for i in range(2,254):
    url=http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html.format(i)
    print(url)

 

2.英文词频统计预处理

story=‘‘‘
‘"Mr.Johnson had never been up in an aerophane before and he had read a lot about air accidents, so one day when a friend offered to take him for a ride in his own small phane, Mr.Johnson was very worried about accepting. Finally, however, his friend persuaded him that it was very safe, and Mr.Johnson boarded the plane.
  His friend started the engine and began to taxi onto the runway of the airport. Mr.Johnson had heard that the most dangerous part of a flight were the take-off and the landing, so he was extremely frightened and closed his eyes.
  After a minute or two he opened them again, looked out of the window of the plane, and said to his friend, "Look at those people down there. They look as small as ants, don‘t they?"
  "Those are ants," answered his friend. "We‘re still on the ground.""
‘‘‘
story=story.lower()
print(story)
story=story.replace(‘?‘,‘ ‘).replace(‘,‘,‘ ‘).replace(‘.‘,‘ ‘).replace(‘!‘,‘ ‘)
print(story)
story=story.split(‘ ‘)
print(story)
str=input("输入要统计的单词:")
count=story.count(str)
print(count)

 

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

标签:bsp   ted   cci   air   ant   color   was   tin   print   

原文地址:https://www.cnblogs.com/pybblog/p/10469793.html

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