大神帮忙看看这个程序怎么写
有一篇文章,共有3行文字,每行有80个字符。要求分别统计出其中英文大写字母、小写字母、数字、空格及其他字符的个数 本帖最后由 jackz007 于 2019-12-3 13:31 编辑#-*-coding:gb2312-*-
str1 = <4 行文本> # 把 4 行文本赋值给 str1
txt = '' . join(x . strip() for x in str1)
cc , lc , dc , bc , oc = 0 , 0 , 0 , 0 , 0
for x in txt:
if 'A' <= x <= 'Z':
cc += 1
elif 'a' <= x <= 'z' :
lc += 1
elif '0' <= x <= '9' :
dc += 1
elif x == ' ':
bc += 1
else:
oc += 1
print('大写字母: %d' % cc)
print('小写字母: %d' % lc)
print('数字字符: %d' % dc)
print('空格字符: %d' % bc)
print('其它字符: %d' % oc) 这是python的解决方法吗
静心五 发表于 2019-12-3 20:16
这是python的解决方法吗
是的。
页:
[1]