zoukankan      html  css  js  c++  java
  • 字符串、文件操作,英文词频统计预处理

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

    该作业要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2646

    1. 字符串操作:

    ·解析身份证号:生日、性别、出生地

     1 id=input("输入身份证号:");
     2 while(len(id)!=18):
     3     print("您的身份证号码输入错误");
     4     id = input("请重新输入您的身份证号:");
     5 biryear=id[6:10];
     6 birmonth=id[10:12];
     7 birday=id[12:14];
     8 print("这个身份证号码的出生日期是{}-{}-{}".format(biryear,birmonth,birday));
     9 sex=id[-2];
    10 if int(sex)%2==0:
    11     print("性别为男");
    12 else:
    13     print("性别为女")
    解析身份证号:生日、性别、出生地

    ·凯撒密码编码与解码

     1 word=input("请输入明文:");
     2 s=ord("a");
     3 e=ord("z");
     4 choose=input("输入数字1执行编码,输入数字2执行解码");
     5 print("根据凯撒密码的规则:",end="")
     6 for i in word:
     7     if s<=ord(i)<=e:
     8         if choose == "1":
     9             print(chr(s+(ord(i)-s+int(3))%26),end="");
    10         elif choose == "2":
    11             print( end="")
    12             print(chr(s + (ord(i)-s-int(3)) % 26), end="");
    13         else:
    14             print("你应该输入数字1或者2")
    15     else:
    16         print(i,end="");
    凯撒密码编码与解码

    ·网址观察与批量生成

    1 for i in range(2,10):
    2     url='http://www.ygdy8.net/html/gndy/china/list_4_{}.html'.format(i)
    3     print(url)
    网址观察与批量生成

    ·英文词频统计预处理

    • 下载一首英文的歌词或文章或小说,保存为utf8文件。

    ·英文词频统计

    • 从文件读出字符串。
    • 将所有大写转换为小写
    • 将所有其他做分隔符(,.?!)替换为空格
    • 分隔出一个一个的单词
    • 并统计单词出现的次数
     1 f=open(r'yellow1.txt','r')
     2 text=f.read()
     3 print(text)
     4 f.close()
     5 lowerText=text.lower()
     6 sep=',?.!-:_'
     7 for s in sep:
     8     text=text.replace(s,' ')
     9 print(lowerText.split())
    10 print()
    11 print('           ',text.count('yellow'))
    英文词频统计

  • 相关阅读:
    POJ 1995
    POJ 3233
    HDU 2815
    POJ 2417
    POJ 3243
    HDU 3579 线性同余方程组
    HDU 1573
    POJ 2115
    POJ 2891
    HDU 2035 不忍直视的水
  • 原文地址:https://www.cnblogs.com/lys1894/p/10482723.html
Copyright © 2011-2022 走看看