接收一个字符串method为参数,根据参数值调用不同函数实现对文本的加密和解密。
method 值为 '统计字符'时,统计并输出文本中不同类型字符的数量并输出。
method 值为 '统计单词'时,统计并输出文本中单词的数量。
method 值为 '首字符'时,将所有单词的首字符提取出来拼接为一个字符串输出。
method 值为 '凯撒加密'时,再输入一个单词做为密钥发生器,用于计算偏移量,对文件中的内容进行加密并输出。
import string
def judge(method, txt):
if method == '1':
classify = classify_char(text)
print('大写字母{}个,小写字母{}个,数字{}个,空格{}个,其他{}个'.format(*classify))
elif method == '2':
word_lst = word_list(text) # 单词的列表
words_counts = number_of_words(word_lst)
print(f'共有{words_counts}单词')
elif method == '3':
word_lst = word_list(text) # 单词的列表
new_str = first_letter(word_lst)
print(f'拼接的字符串是{new_str}')
elif method == '4':
key = input('