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

    本次作业要求来自于:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2684

    1.字符串操作:

    • 解析身份证号:生日、性别、出生地等。
    file = open('region.txt','r')
    text = file.read()
    file.close()
    text = text.replace('u3000','')
    list = text.split('
    ')
    print(list)
    Id=input('请输入身份证号码:')
    for areaVerify in list:
            if Id[0:6] == areaVerify[0:6]:
                city = areaVerify[6:]
    Birth_year = Id[6:10]
    Birth_month = Id[10:12]
    Birth_day = Id[12:14]
    sex = '' if int(Id[16]) % 2 == 0 else ''
    print('{},出生于{}年{}月{}日,{}人'.format(sex,Birth_year,Birth_month,Birth_day,city))

    • 凯撒密码编码与解码
    Plaintext=input('请输入明文:')
    pas=''
    pla=''
    print('密文为:',end='')
    for i in range(0, len(Plaintext)):
        if Plaintext[i] in ['x', 'y', 'z']:
            pas += chr(ord(Plaintext[i]) - 23)
        else:
            pas += chr(ord(Plaintext[i]) + 3)
    print(pas,end='')
    print('
    原文为:',end='')
    for i in range(0,len(pas)):
        if pas[i] in ['a','b','c']:
            pla += chr(ord(pas[i]) + 23)
        else:
            pla += chr(ord(pas[i])-3)
    print(pla,end='')
    

      

    • 网址观察与批量生成 
    for i in range(2,6):
        url='http://news.gzcc.cn/html/xiaoyuanxinwen/{}.html'.format(i)
        print(url)
    import webbrowser as web
    for i in range(2,6):
        web.open_new_tab('http://news.gzcc.cn/html/xiaoyuanxinwen/'+ str(i) +'.html')
    

      

     2.英文词频统计预处理

    text='''For you I gave my life, my everything,
    you were my reason why
    And you were true to me,
    and in our darkest hour,
    your love set me free
    You were the only one for me,
    what love was meant to be
    Forever you will be my love, all I need
    Our dreams of life together gone,
    I don’t know what went wrong
    I will miss you forever my love
    I feel so lonely without you
    I don’t know what to do
    Cause you were everything to me, yeah it’s true
    The light that shined into my life
    The fire that stirs desire
    Burning out like a flame in the night
    You were the only one for me,
    what love was meant to be
    Forever you will be my love, all I need
    Our dreams of life together gone,
    I don’t know what went wrong
    I will miss you forever my love
    And now, I walk alone
    An empty heart, the precious moments gone
    But I know that you are there
    one day when heaven calls, I’ll see you again
    when heaven calls, I’ll see you again'''
    text = text.lower()
    pun =  ',.?!
    '
    for i in pun:
         text = text.replace(i,' ')
    words = text.split(' ')
    print(words)
    word_count = {}
    for word in words:
        if word in word_count.keys():
            word_count[word] += 1
        else:
            word_count[word] = 1
    print('单词                个数')
    for i in word_count:
        print('{:<20}{:<8}'.format(i,word_count[i]))
    

      

  • 相关阅读:
    selector
    Shape 属性解释
    Button 自定义图片,代码绘制样式,添加音效的方法
    android中得到颜色,图片资源的方式
    EditText 中文文档
    EditText 限制输入,自定义样式,监听输入的字符,自动换行
    TextView字体,行距,html格式,超链接,对大长度的设定
    TextView 中文文档
    Eclipse 汉化的和修改字体的方法
    让Android SDK Manager正常更新的办法
  • 原文地址:https://www.cnblogs.com/LinsenLiang/p/10513119.html
Copyright © 2011-2022 走看看