#计数.py(P104_3_1)
#I
Str=input('请输入一段字符:')
char=0
space=0
num=0
other=0
#p
for i in Str :
if ((i>'A' and i<'Z') or (i>'a' and i<'z')): #查找字母
char=char+1 #char+=1 #字母个数累加(char+=1)
elif (i==' '): #查找空格
space=space+1
elif (i>'0' and i<'9'): #查找数字
num=num+1
else: #查找其他内容
other=other+1
#O
print('字母: %d' %char )
print('空格: %d' %space)
print('数字: %d' %num)
print('其他: %d' %other )
该程序用于统计输入字符串中字母、空格、数字和其他字符的数量。通过遍历字符串,分别计算各类字符的个数,并输出结果。此代码适用于文本分析和基础字符统计任务。
420

被折叠的 条评论
为什么被折叠?



