当前位置:   article > 正文

Python课后作业 3. 文本分析与加密 ---- (第七次作业)_python123文本分析与加密

python123文本分析与加密


前引


原本我认为这道题会很难
其实之后做完才发现并没有那么难…
没什么思路 会点python的应该都看得懂我的代码
代码很直白 不拐弯抹角
就这样了


原题题目


在这里插入图片描述


代码实现

def encrypating(character,n):
    if character.islower():temp = ord('a');character = chr(temp+(ord(character)-temp+n)%26)
    else:temp = ord('A');character = chr(temp+(ord(character)-temp+n)%26)
    return character

l = list(str(input()));secret = 0
for i in l:
    secret = (secret + ord(i))%26

f = open("mayun.txt","r")
content = f.readlines()
upperchr = lowerchr = num = space = others = words = 0

for line in content:
    for i in line:
        if i.isupper():upperchr+=1
        elif i.islower():lowerchr+=1
        elif i.isspace():space+=1
        elif i.isdigit():num+=1
        else:others+=1
    str = line.replace('.', '')
    str = str.replace(',', '')
    str = str.replace("'", '')
    l = list(str.split(' '))
    words+=len(l)
print("%d %d %d %d %d"%(upperchr,lowerchr,num,space,others))
print("%d words in all"% words)
print("%d"% secret)

for line in content:
    ret = ""
    for char in line:
        if char.isalpha():ret += encrypating(char,secret)
        elif char != '\n':ret += char
    print(ret)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

提交结果

在这里插入图片描述

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/674227
推荐阅读
相关标签
  

闽ICP备14008679号