任务描述
本关任务:读取附件中的文件,统计文件中大写字母、小写字母、数字、空白字符和其他字符的数量。
输出格式
文件中大写字母、小写字母、数字、空白字符和其他字符的数量;
相关知识
Python 读取文件
读取文件中的内容为字符串可以用以下函数实现:
def classify_char(txt):
upper, lower, digit, space, other = 0, 0, 0, 0, 0
for ch in txt:
if ch.islower():
lower = lower + 1
elif ch.isupper():
upper = upper + 1
elif ch.isnumeric():
digit = digit + 1
elif ch.isspace():
space = space + 1
else:
other = other + 1
return upper, lower, digit, space, other
编程要求
在右侧编辑器中的 Begin-End 区间补充代码,具体要求如下:
读取本地的 mayun.txt 文件,返回字符串
上一篇:谌贻琴南下,专门关注了这件事 谌贻琴南下,专门关注了这件事
下一篇:18亿元股权转让前妻!A股天价离婚案频发,一年内8起离婚案“分手费”过亿 a股天价离婚案分走34亿 1.35亿元a股再现天价离婚案